Skip to content

Commit 54592e5

Browse files
committed
fix: get codepoint range rather than bytes
1 parent e65cfc9 commit 54592e5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/constructor_parser.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,13 @@ impl<'a> ConstructorStringParser<'a> {
167167
assert!(self.token_index < self.token_list.len());
168168
let token = &self.token_list[self.token_index];
169169
let component_start_index = self.get_safe_token(self.component_start).index;
170+
170171
self
171172
.input
172-
.get(component_start_index..token.index) // TODO: check & codepoint
173-
.unwrap()
174-
.to_string()
173+
.chars()
174+
.skip(component_start_index)
175+
.take(token.index - component_start_index)
176+
.collect()
175177
}
176178

177179
// Ref: https://wicg.github.io/urlpattern/#rewind-and-set-state

src/testdata/urlpatterntestdata.json

+10
Original file line numberDiff line numberDiff line change
@@ -2721,5 +2721,15 @@
27212721
"expected_match": {
27222722
"pathname": { "input": "/bazbar", "groups": { "foo": "baz" }}
27232723
}
2724+
},
2725+
{
2726+
"pattern": [":café://:foo"],
2727+
"exactly_empty_components": [ "username", "password", "port", "search",
2728+
"hash" ],
2729+
"expected_obj": {
2730+
"protocol": ":café",
2731+
"hostname": ":foo",
2732+
"pathname": "/"
2733+
}
27242734
}
27252735
]

0 commit comments

Comments
 (0)