File tree Expand file tree Collapse file tree 3 files changed +30
-10
lines changed Expand file tree Collapse file tree 3 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ jobs:
100
100
echo "Running tests with $sanitizer sanitizer..."
101
101
export RUSTFLAGS="-Z sanitizer=$sanitizer"
102
102
export RUSTDOCFLAGS="$RUSTFLAGS"
103
- cargo +nightly test -Z build-std --target "$TARGET"
103
+ cargo +nightly test -Z build-std --target "$TARGET" --lib --tests
104
104
done
105
105
106
106
WASM :
Original file line number Diff line number Diff line change @@ -151,16 +151,27 @@ impl<'a> Host<Cow<'a, str>> {
151
151
} ;
152
152
153
153
if input. find ( is_invalid_host_char) . is_some ( ) {
154
- Err ( ParseError :: InvalidDomainCharacter )
155
- } else {
156
- Ok ( Host :: Domain (
157
- match utf8_percent_encode ( & input, CONTROLS ) . into ( ) {
158
- Cow :: Owned ( v) => Cow :: Owned ( v) ,
159
- // if we're borrowing, then we can return the original Cow
160
- Cow :: Borrowed ( _) => input,
161
- } ,
162
- ) )
154
+ return Err ( ParseError :: InvalidDomainCharacter ) ;
163
155
}
156
+
157
+ // Call utf8_percent_encode and use the result.
158
+ // Note: This returns Cow::Borrowed for single-item results (either from input
159
+ // or from the static encoding table), and Cow::Owned for multi-item results.
160
+ // We cannot distinguish between "borrowed from input" vs "borrowed from static table"
161
+ // based on the Cow variant alone.
162
+ Ok ( Host :: Domain (
163
+ match utf8_percent_encode ( & input, CONTROLS ) . into ( ) {
164
+ Cow :: Owned ( v) => Cow :: Owned ( v) ,
165
+ // If we're borrowing, we need to check if it's the same as the input
166
+ Cow :: Borrowed ( v) => {
167
+ if v == & * input {
168
+ input // No encoding happened, reuse original
169
+ } else {
170
+ Cow :: Owned ( v. to_owned ( ) ) // Borrowed from static table, need to own it
171
+ }
172
+ }
173
+ } ,
174
+ ) )
164
175
}
165
176
166
177
pub ( crate ) fn into_owned ( self ) -> Host < String > {
Original file line number Diff line number Diff line change @@ -1383,3 +1383,12 @@ fn serde_error_message() {
1383
1383
r#"relative URL without a base: "§invalid#+#*Ä" at line 1 column 25"#
1384
1384
) ;
1385
1385
}
1386
+
1387
+ #[ test]
1388
+ fn test_parse_url_with_single_byte_control_host ( ) {
1389
+ let input = "l://\x01 :" ;
1390
+
1391
+ let url1 = Url :: parse ( input) . unwrap ( ) ;
1392
+ let url2 = Url :: parse ( url1. as_str ( ) ) . unwrap ( ) ;
1393
+ assert_eq ! ( url2, url1) ;
1394
+ }
You can’t perform that action at this time.
0 commit comments