Antonio-Maranhao closed pull request #1161: Fix cancel link URL when ddoc name 
has special chars
URL: https://github.com/apache/couchdb-fauxton/pull/1161
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/app/addons/documents/index-editor/__tests__/components.test.js 
b/app/addons/documents/index-editor/__tests__/components.test.js
index a3d4c207c..33936d751 100644
--- a/app/addons/documents/index-editor/__tests__/components.test.js
+++ b/app/addons/documents/index-editor/__tests__/components.test.js
@@ -243,6 +243,17 @@ describe('IndexEditor', () => {
     sinon.assert.calledWith(spy, 'newViewName');
   });
 
+  it('generates the correct cancel link when db, ddoc and views have special 
chars', () => {
+    const editorEl = mount(<Views.IndexEditor
+      {...defaultProps}
+      database={{ id: 'db%$1' }}
+      designDocId={'_design/doc/1$2'}
+      viewName={'v?abc/123'}
+    />);
+    const expectedUrl = 
`/${encodeURIComponent('db%$1')}/_design/${encodeURIComponent('doc/1$2')}/_view/${encodeURIComponent('v?abc/123')}`;
+    
expect(editorEl.find('a.index-cancel-link').prop('href')).toMatch(expectedUrl);
+  });
+
   it('shows warning when trying to save a partitioned view with custom 
reduce', () => {
     sinon.stub(FauxtonAPI, 'addNotification');
     const editorEl = mount(<Views.IndexEditor
diff --git a/app/addons/documents/index-editor/components/IndexEditor.js 
b/app/addons/documents/index-editor/components/IndexEditor.js
index 2d1a2cc46..b2a14bf5c 100644
--- a/app/addons/documents/index-editor/components/IndexEditor.js
+++ b/app/addons/documents/index-editor/components/IndexEditor.js
@@ -98,11 +98,13 @@ export default class IndexEditor extends Component {
   getCancelLink() {
     const encodedDatabase = encodeURIComponent(this.props.database.id);
     const encodedPartitionKey = this.props.partitionKey ? 
encodeURIComponent(this.props.partitionKey) : '';
-    const encodedDDoc = encodeURIComponent(this.props.designDocId);
-    const encodedView = encodeURIComponent(this.props.viewName);
     if (this.props.designDocId === 'new-doc' || this.props.isNewView) {
       return '#' + FauxtonAPI.urls('allDocs', 'app', encodedDatabase, 
encodedPartitionKey);
     }
+    const encodedDDoc = this.props.designDocId.startsWith('_design/') ?
+      '_design/' + encodeURIComponent(this.props.designDocId.substring(8)) :
+      encodeURIComponent(this.props.designDocId);
+    const encodedView = encodeURIComponent(this.props.viewName);
     return '#' + FauxtonAPI.urls('view', 'showView', encodedDatabase, 
encodedPartitionKey, encodedDDoc, encodedView);
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to