Skip to content

Commit 7eccac9

Browse files
authored
Add a test for and fix issue #974 (#975)
* Add a test for issue 974 * Fix the issue * rename test
1 parent 710e1e7 commit 7eccac9

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

url/src/parser.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,11 @@ impl<'a> Parser<'a> {
11201120
}
11211121
input = remaining;
11221122
}
1123+
1124+
if !has_any_digit && context == Context::Setter && !input.is_empty() {
1125+
return Err(ParseError::InvalidPort);
1126+
}
1127+
11231128
let mut opt_port = Some(port as u16);
11241129
if !has_any_digit || opt_port == default_port() {
11251130
opt_port = None;

url/tests/expected_failures.txt

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
<non-spec:/.//p> set hostname to <h>
4040
<non-spec:/.//p> set hostname to <>
4141
<foo:///some/path> set pathname to <>
42-
<http://example.net:8080/path> set port to <randomstring>
4342
<file:///var/log/system.log> set href to <http://0300.168.0xF0>
4443
<file://monkey/> set pathname to <\\\\>
4544
<file:///unicorn> set pathname to <//\\/>

url/tests/unit.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1316,3 +1316,10 @@ fn issue_864() {
13161316
url.set_path("x");
13171317
dbg!(&url);
13181318
}
1319+
1320+
#[test]
1321+
fn issue_974() {
1322+
let mut url = url::Url::parse("http://example.com:8000").unwrap();
1323+
let _ = url::quirks::set_port(&mut url, "\u{0000}9000");
1324+
assert_eq!(url.port(), Some(8000));
1325+
}

0 commit comments

Comments
 (0)