Skip to content

Commit

Permalink
Auto merge of #408 - valenting:path-percent-2e, r=SimonSapin
Browse files Browse the repository at this point in the history
Don't percent decode %2e all the time in the path

Implements whatwg/url#156

Imports tests from: web-platform-tests/wpt@d93247d

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/408)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored Nov 1, 2017
2 parents 222c34c + fef3156 commit 380be29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
13 changes: 2 additions & 11 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,15 +920,6 @@ impl<'a> Parser<'a> {
},
_ => {
self.check_url_code_point(c, &input);
if c == '%' {
let after_percent_sign = input.clone();
if matches!(input.next(), Some('2')) &&
matches!(input.next(), Some('E') | Some('e')) {
self.serialization.push('.');
continue
}
input = after_percent_sign
}
if self.context == Context::PathSegmentSetter {
self.serialization.extend(utf8_percent_encode(
utf8_c, PATH_SEGMENT_ENCODE_SET));
Expand All @@ -940,15 +931,15 @@ impl<'a> Parser<'a> {
}
}
match &self.serialization[segment_start..] {
".." => {
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e" | ".%2E" => {
debug_assert!(self.serialization.as_bytes()[segment_start - 1] == b'/');
self.serialization.truncate(segment_start - 1); // Truncate "/.."
self.pop_path(scheme_type, path_start);
if !self.serialization[path_start..].ends_with('/') {
self.serialization.push('/')
}
},
"." => {
"." | "%2e" | "%2E" => {
self.serialization.truncate(segment_start);
},
_ => {
Expand Down
10 changes: 5 additions & 5 deletions tests/setters_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,8 @@
"href": "view-source+http://example.net/home?lang=fr#nav",
"new_value": "\\a\\%2E\\b\\%2e.\\c",
"expected": {
"href": "view-source+http://example.net/\\a\\.\\b\\..\\c?lang=fr#nav",
"pathname": "/\\a\\.\\b\\..\\c"
"href": "view-source+http://example.net/\\a\\%2E\\b\\%2e.\\c?lang=fr#nav",
"pathname": "/\\a\\%2E\\b\\%2e.\\c"
}
},
{
Expand All @@ -984,12 +984,12 @@
}
},
{
"comment": "Bytes already percent-encoded are left as-is, except %2E.",
"comment": "Bytes already percent-encoded are left as-is, including %2E outside dotted segments.",
"href": "http://example.net",
"new_value": "%2e%2E%c3%89té",
"expected": {
"href": "http://example.net/..%c3%89t%C3%A9",
"pathname": "/..%c3%89t%C3%A9"
"href": "http://example.net/%2e%2E%c3%89t%C3%A9",
"pathname": "/%2e%2E%c3%89t%C3%A9"
}
}
],
Expand Down
12 changes: 6 additions & 6 deletions tests/urltestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -1845,30 +1845,30 @@
{
"input": "http://example.com/foo/%2e%2",
"base": "about:blank",
"href": "http://example.com/foo/.%2",
"href": "http://example.com/foo/%2e%2",
"origin": "http://example.com",
"protocol": "http:",
"username": "",
"password": "",
"host": "example.com",
"hostname": "example.com",
"port": "",
"pathname": "/foo/.%2",
"pathname": "/foo/%2e%2",
"search": "",
"hash": ""
},
{
"input": "http://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar",
"base": "about:blank",
"href": "http://example.com/..bar",
"href": "http://example.com/%2e.bar",
"origin": "http://example.com",
"protocol": "http:",
"username": "",
"password": "",
"host": "example.com",
"hostname": "example.com",
"port": "",
"pathname": "/..bar",
"pathname": "/%2e.bar",
"search": "",
"hash": ""
},
Expand Down Expand Up @@ -2286,15 +2286,15 @@
{
"input": "http://www/foo%2Ehtml",
"base": "about:blank",
"href": "http://www/foo.html",
"href": "http://www/foo%2Ehtml",
"origin": "http://www",
"protocol": "http:",
"username": "",
"password": "",
"host": "www",
"hostname": "www",
"port": "",
"pathname": "/foo.html",
"pathname": "/foo%2Ehtml",
"search": "",
"hash": ""
},
Expand Down

0 comments on commit 380be29

Please sign in to comment.