Repository: jira-node/node-jira-client (js)

Issue:
URL is not encoded, using special characters is broken (æøå)
When trying to download attachments with special characters in the filename, Jira responds with error 400.
This cannot be fixed by encoding the filename outside the library, this is reverted later.
URL should be encoded.

Pull request:
fix encoding for attachments. 
I'm open to doing this in a more general way - but this seemed liked the simplest solution. 

Patch:
diff --git a/src/jira.js b/src/jira.js
index 1e7b6fe..23cef5f 100644
--- a/src/jira.js
+++ b/src/jira.js
@@ -142,7 +142,9 @@ export default class JiraApi {
    * Creates a URI object for a given pathname
    * @param {object} [options] - an object containing path information
    */
-  makeUri({ pathname, query, intermediatePath }) {
+  makeUri({
+    pathname, query, intermediatePath, encode = false,
+  }) {
     const intermediateToUse = this.intermediatePath || intermediatePath;
     const tempPath = intermediateToUse || `/rest/api/${this.apiVersion}`;
     const uri = url.format({
@@ -152,7 +154,7 @@ export default class JiraApi {
       pathname: `${this.base}${tempPath}${pathname}`,
       query,
     });
-    return decodeURIComponent(uri);
+    return encode ? encodeURI(uri) : decodeURIComponent(uri);
   }
 
   /**
@@ -315,6 +317,7 @@ export default class JiraApi {
     return this.doRequest(this.makeRequestHeader(this.makeUri({
       pathname: `/attachment/${attachment.id}/${attachment.filename}`,
       intermediatePath: '/secure',
+      encode: true,
     }), { json: false, encoding: null }));
   }
 


Test patch:
diff --git a/test/jira-tests.js b/test/jira-tests.js
index 240c930..395a220 100644
--- a/test/jira-tests.js
+++ b/test/jira-tests.js
@@ -407,6 +407,11 @@ describe('Jira API Tests', () => {
       result.should.eql('http://jira.somehost.com:8080/secure/attachment/123456/attachment.txt');
     });
 
+    it('downloadAttachment hits proper url with attachment id and filename with special characters', async () => {
+      const result = await dummyURLCall('downloadAttachment', [{ id: '123456', filename: 'attachment-æøå.txt' }]);
+      result.should.eql('http://jira.somehost.com:8080/secure/attachment/123456/attachment-%C3%A6%C3%B8%C3%A5.txt');
+    });
+
     it('getUnresolvedIssueCount hits proper url', async () => {
       async function dummyRequest(requestOptions) {
         return { issuesUnresolvedCount: requestOptions };