소스 검색

Stop percent decoding %2e all the time

Valentin Gosu 9 년 전
부모
커밋
63e12b0b43
2개의 변경된 파일7개의 추가작업 그리고 16개의 파일을 삭제
  1. 2 11
      src/parser.rs
  2. 5 5
      tests/setters_tests.json

+ 2 - 11
src/parser.rs

@@ -920,15 +920,6 @@ impl<'a> Parser<'a> {
                     },
                     },
                     _ => {
                     _ => {
                         self.check_url_code_point(c, &input);
                         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 {
                         if self.context == Context::PathSegmentSetter {
                             self.serialization.extend(utf8_percent_encode(
                             self.serialization.extend(utf8_percent_encode(
                                 utf8_c, PATH_SEGMENT_ENCODE_SET));
                                 utf8_c, PATH_SEGMENT_ENCODE_SET));
@@ -940,7 +931,7 @@ impl<'a> Parser<'a> {
                 }
                 }
             }
             }
             match &self.serialization[segment_start..] {
             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'/');
                     debug_assert!(self.serialization.as_bytes()[segment_start - 1] == b'/');
                     self.serialization.truncate(segment_start - 1);  // Truncate "/.."
                     self.serialization.truncate(segment_start - 1);  // Truncate "/.."
                     self.pop_path(scheme_type, path_start);
                     self.pop_path(scheme_type, path_start);
@@ -948,7 +939,7 @@ impl<'a> Parser<'a> {
                         self.serialization.push('/')
                         self.serialization.push('/')
                     }
                     }
                 },
                 },
-                "." => {
+                "." | "%2e" | "%2E" => {
                     self.serialization.truncate(segment_start);
                     self.serialization.truncate(segment_start);
                 },
                 },
                 _ => {
                 _ => {

+ 5 - 5
tests/setters_tests.json

@@ -970,8 +970,8 @@
             "href": "view-source+http://example.net/home?lang=fr#nav",
             "href": "view-source+http://example.net/home?lang=fr#nav",
             "new_value": "\\a\\%2E\\b\\%2e.\\c",
             "new_value": "\\a\\%2E\\b\\%2e.\\c",
             "expected": {
             "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"
             }
             }
         },
         },
         {
         {
@@ -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",
             "href": "http://example.net",
             "new_value": "%2e%2E%c3%89té",
             "new_value": "%2e%2E%c3%89té",
             "expected": {
             "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"
             }
             }
         }
         }
     ],
     ],