Skip to content

Commit

Permalink
Add a test for and fix issue #974 (#975)
Browse files Browse the repository at this point in the history
* Add a test for issue 974

* Fix the issue

* rename test
  • Loading branch information
hansl authored Sep 30, 2024
1 parent 710e1e7 commit 7eccac9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions url/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,11 @@ impl<'a> Parser<'a> {
}
input = remaining;
}

if !has_any_digit && context == Context::Setter && !input.is_empty() {
return Err(ParseError::InvalidPort);
}

let mut opt_port = Some(port as u16);
if !has_any_digit || opt_port == default_port() {
opt_port = None;
Expand Down
1 change: 0 additions & 1 deletion url/tests/expected_failures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<non-spec:/.//p> set hostname to <h>
<non-spec:/.//p> set hostname to <>
<foo:///some/path> set pathname to <>
<http://example.net:8080/path> set port to <randomstring>
<file:///var/log/system.log> set href to <http://0300.168.0xF0>
<file://monkey/> set pathname to <\\\\>
<file:///unicorn> set pathname to <//\\/>
Expand Down
7 changes: 7 additions & 0 deletions url/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,3 +1316,10 @@ fn issue_864() {
url.set_path("x");
dbg!(&url);
}

#[test]
fn issue_974() {
let mut url = url::Url::parse("http://example.com:8000").unwrap();
let _ = url::quirks::set_port(&mut url, "\u{0000}9000");
assert_eq!(url.port(), Some(8000));
}

0 comments on commit 7eccac9

Please sign in to comment.