Bug 1042347 - %2e entered in URL bar not normalized leading to denormalized request r=mcmanus

This commit is contained in:
Valentin Gosu 2016-02-10 13:13:23 +01:00
parent 967c5babae
commit 73f17fbac5
4 changed files with 32 additions and 42 deletions

View File

@ -248,7 +248,7 @@ net_CoalesceDirs(netCoalesceFlags flags, char* path)
*/
char *fwdPtr = path;
char *urlPtr = path;
char *lastslash = path;
char *endPath = path;
uint32_t traversal = 0;
uint32_t special_ftp_len = 0;
@ -265,34 +265,18 @@ net_CoalesceDirs(netCoalesceFlags flags, char* path)
special_ftp_len = 2;
}
/* find the last slash before # or ? */
for(; (*fwdPtr != '\0') &&
(*fwdPtr != '?') &&
/* find the end of the path - places the cursor on \0, ? or # */
for(; (*fwdPtr != '\0') &&
(*fwdPtr != '?') &&
(*fwdPtr != '#'); ++fwdPtr)
{
}
/* found nothing, but go back one only */
/* if there is something to go back to */
if (fwdPtr != path && *fwdPtr == '\0')
{
--fwdPtr;
}
/* search the slash */
for(; (fwdPtr != path) &&
(*fwdPtr != '/'); --fwdPtr)
{
}
lastslash = fwdPtr;
endPath = fwdPtr;
fwdPtr = path;
/* replace all %2E or %2e with . in the path */
/* but stop at lastchar if non null */
for(; (*fwdPtr != '\0') &&
(*fwdPtr != '?') &&
(*fwdPtr != '#') &&
(*lastslash == '\0' || fwdPtr != lastslash); ++fwdPtr)
for(; fwdPtr != endPath; ++fwdPtr)
{
if (*fwdPtr == '%' && *(fwdPtr+1) == '2' &&
(*(fwdPtr+2) == 'E' || *(fwdPtr+2) == 'e'))

View File

@ -301,6 +301,32 @@ add_test(function test_hugeStringThrows()
run_next_test();
});
add_test(function test_pathPercentEncodedDot()
{
var url = stringToURL("http://example.com/%2eX/X%2e/%2eX");
do_check_eq(url.spec, "http://example.com/.X/X./.X");
url = stringToURL("http://example.com/hello/%2e%2E/%2e");
do_check_eq(url.spec, "http://example.com/");
url = stringToURL("http://example.com/hello/%2e%2E/%");
do_check_eq(url.spec, "http://example.com/%");
url = stringToURL("http://example.com/hello/%2e%2E/%2");
do_check_eq(url.spec, "http://example.com/%2");
url = stringToURL("http://example.com/hello/%2e%2E/%#");
do_check_eq(url.spec, "http://example.com/%#");
url = stringToURL("http://example.com/hello/%2e%2E/%2?");
do_check_eq(url.spec, "http://example.com/%2?");
url = stringToURL("http://example.com/hello/%2e/");
do_check_eq(url.spec, "http://example.com/hello/");
run_next_test();
});
add_test(function test_filterWhitespace()
{
var url = stringToURL(" \r\n\th\nt\rt\tp://ex\r\n\tample.com/path\r\n\t/\r\n\tto the/fil\r\n\te.e\r\n\txt?que\r\n\try#ha\r\n\tsh \r\n\t ");

View File

@ -147,9 +147,6 @@
[Parsing: <file://localhost/test> against <file:///tmp/mock/path>]
expected: FAIL
[Parsing: <http://example.com/foo/%2e> against <about:blank>]
expected: FAIL
[Parsing: <http://example.com\\\\foo\\\\bar> against <about:blank>]
expected: FAIL
@ -500,10 +497,3 @@
[Parsing: <file:a> against <http://www.example.com/test>]
expected: FAIL
[Parsing: <http://example.com/foo/%2e%2> against <about:blank>]
expected: FAIL
[Parsing: <http://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar> against <about:blank>]
expected: FAIL

View File

@ -96,9 +96,6 @@
[Parsing: <file://localhost/test> against <file:///tmp/mock/path>]
expected: FAIL
[Parsing: <http://example.com/foo/%2e> against <about:blank>]
expected: FAIL
[Parsing: <http://example.com\\\\foo\\\\bar> against <about:blank>]
expected: FAIL
@ -341,10 +338,3 @@
[Parsing: <file:a> against <http://www.example.com/test>]
expected: FAIL
[Parsing: <http://example.com/foo/%2e%2> against <about:blank>]
expected: FAIL
[Parsing: <http://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar> against <about:blank>]
expected: FAIL