From 117441007609506961bf7c05cde004c417899f17 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Thu, 16 Apr 2015 01:11:05 +0300 Subject: [PATCH] Bug 1040285 - Single Quotes should not be encoded in the path. r=mcmanus, r=annevk --- netwerk/test/unit/test_bug376844.js | 2 +- netwerk/test/unit/test_standardurl.js | 9 +++++++++ toolkit/components/osfile/modules/ospath_unix.jsm | 4 ++-- xpcom/io/nsEscape.cpp | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/netwerk/test/unit/test_bug376844.js b/netwerk/test/unit/test_bug376844.js index b72bac6479a..9a21b0171e2 100644 --- a/netwerk/test/unit/test_bug376844.js +++ b/netwerk/test/unit/test_bug376844.js @@ -1,7 +1,7 @@ const testURLs = [ ["http://example.com/<", "http://example.com/%3C"], ["http://example.com/>", "http://example.com/%3E"], - ["http://example.com/'", "http://example.com/%27"], + ["http://example.com/'", "http://example.com/'"], ["http://example.com/\"", "http://example.com/%22"], ["http://example.com/?<", "http://example.com/?%3C"], ["http://example.com/?>", "http://example.com/?%3E"], diff --git a/netwerk/test/unit/test_standardurl.js b/netwerk/test/unit/test_standardurl.js index d32b37e84ca..81de347b1be 100644 --- a/netwerk/test/unit/test_standardurl.js +++ b/netwerk/test/unit/test_standardurl.js @@ -235,6 +235,14 @@ function test_escapeQueryBrackets() do_check_eq(url.spec, "http://[2001::1]/?a%5Bx%5D=1"); } +function test_apostropheEncoding() +{ + // For now, single quote is escaped everywhere _except_ the path. + // This policy is controlled by the bitmask in nsEscape.cpp::EscapeChars[] + var url = stringToURL("http://example.com/dir'/file'.ext'"); + do_check_eq(url.spec, "http://example.com/dir'/file'.ext'"); +} + function run_test() { test_setEmptyPath(); @@ -244,4 +252,5 @@ function run_test() test_ipv6_fail(); test_clearedSpec(); test_escapeQueryBrackets(); + test_apostropheEncoding(); } diff --git a/toolkit/components/osfile/modules/ospath_unix.jsm b/toolkit/components/osfile/modules/ospath_unix.jsm index d64e215268d..6e0f00d5621 100644 --- a/toolkit/components/osfile/modules/ospath_unix.jsm +++ b/toolkit/components/osfile/modules/ospath_unix.jsm @@ -163,14 +163,14 @@ exports.split = split; * Returns the file:// URI file path of the given local file path. */ // The case of %3b is designed to match Services.io, but fundamentally doesn't matter. -let toFileURIExtraEncodings = {';': '%3b', '?': '%3F', "'": '%27', '#': '%23'}; +let toFileURIExtraEncodings = {';': '%3b', '?': '%3F', '#': '%23'}; let toFileURI = function toFileURI(path) { let uri = encodeURI(this.normalize(path)); // add a prefix, and encodeURI doesn't escape a few characters that we do // want to escape, so fix that up let prefix = "file://"; - uri = prefix + uri.replace(/[;?'#]/g, match => toFileURIExtraEncodings[match]); + uri = prefix + uri.replace(/[;?#]/g, match => toFileURIExtraEncodings[match]); return uri; }; diff --git a/xpcom/io/nsEscape.cpp b/xpcom/io/nsEscape.cpp index 8042d97974b..2a9698458b5 100644 --- a/xpcom/io/nsEscape.cpp +++ b/xpcom/io/nsEscape.cpp @@ -360,7 +360,7 @@ static const uint32_t EscapeChars[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x - 0,1023, 0, 512,1023, 0,1023, 0,1023,1023,1023,1023,1023,1023, 953, 784, // 2x !"#$%&'()*+,-./ + 0,1023, 0, 512,1023, 0,1023, 112,1023,1023,1023,1023,1023,1023, 953, 784, // 2x !"#$%&'()*+,-./ 1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1008,1008, 0,1008, 0, 768, // 3x 0123456789:;<=>? 1008,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, // 4x @ABCDEFGHIJKLMNO 1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 896, 896, 896, 896,1023, // 5x PQRSTUVWXYZ[\]^_