From 39e3e75879eb0cac054c5d342b6ec9e7bda297d8 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Mon, 2 Nov 2015 13:54:59 +0100 Subject: [PATCH] Bug 1163028 - stop escaping [ and ] in toFileURI r=yoric --- toolkit/components/osfile/modules/ospath_unix.jsm | 5 ++++- toolkit/components/osfile/modules/ospath_win.jsm | 5 ++++- .../osfile/tests/xpcshell/test_file_URL_conversion.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/toolkit/components/osfile/modules/ospath_unix.jsm b/toolkit/components/osfile/modules/ospath_unix.jsm index 4199ead628b2..119e982b0e75 100644 --- a/toolkit/components/osfile/modules/ospath_unix.jsm +++ b/toolkit/components/osfile/modules/ospath_unix.jsm @@ -165,7 +165,10 @@ exports.split = split; // The case of %3b is designed to match Services.io, but fundamentally doesn't matter. var toFileURIExtraEncodings = {';': '%3b', '?': '%3F', '#': '%23'}; var toFileURI = function toFileURI(path) { - let uri = encodeURI(this.normalize(path)); + // Per https://url.spec.whatwg.org we should not encode [] in the path + let dontNeedEscaping = {'%5B': '[', '%5D': ']'}; + let uri = encodeURI(this.normalize(path)).replace(/%(5B|5D)/gi, + match => dontNeedEscaping[match]); // add a prefix, and encodeURI doesn't escape a few characters that we do // want to escape, so fix that up diff --git a/toolkit/components/osfile/modules/ospath_win.jsm b/toolkit/components/osfile/modules/ospath_win.jsm index 98cab2c65ab7..9c5a7b30d552 100644 --- a/toolkit/components/osfile/modules/ospath_win.jsm +++ b/toolkit/components/osfile/modules/ospath_win.jsm @@ -310,7 +310,10 @@ var toFileURIExtraEncodings = {';': '%3b', '?': '%3F', '#': '%23'}; var toFileURI = function toFileURI(path) { // URI-escape forward slashes and convert backward slashes to forward path = this.normalize(path).replace(/[\\\/]/g, m => (m=='\\')? '/' : '%2F'); - let uri = encodeURI(path); + // Per https://url.spec.whatwg.org we should not encode [] in the path + let dontNeedEscaping = {'%5B': '[', '%5D': ']'}; + let uri = encodeURI(path).replace(/%(5B|5D)/gi, + match => dontNeedEscaping[match]); // add a prefix, and encodeURI doesn't escape a few characters that we do // want to escape, so fix that up diff --git a/toolkit/components/osfile/tests/xpcshell/test_file_URL_conversion.js b/toolkit/components/osfile/tests/xpcshell/test_file_URL_conversion.js index 4ef1fbce9bda..3ec42065bdb8 100644 --- a/toolkit/components/osfile/tests/xpcshell/test_file_URL_conversion.js +++ b/toolkit/components/osfile/tests/xpcshell/test_file_URL_conversion.js @@ -54,7 +54,7 @@ function run_test() { '/test;+%', '/test?action=index/', '/test\ test', - '/punctuation/;,/?:@&=+$-_.!~*\'()"#', + '/punctuation/;,/?:@&=+$-_.!~*\'()[]"#', '/CasePreserving' ];