Bug 1040285 - Single Quotes should not be encoded in the path. r=mcmanus, r=annevk

This commit is contained in:
Valentin Gosu 2015-04-16 01:11:05 +03:00
parent 71b80226cb
commit 1174410076
4 changed files with 13 additions and 4 deletions

View File

@ -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"],

View File

@ -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();
}

View File

@ -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;
};

View File

@ -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[\]^_