Skip to content

Commit 1ced3e6

Browse files
authored
Properly enforce host_required for URLs (#1488)
1 parent 92a259e commit 1ced3e6

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.github/workflows/codspeed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
jobs:
1313
benchmarks:
14-
runs-on: ubuntu-latest
14+
runs-on: ubuntu-22.04
1515

1616
steps:
1717
- uses: actions/checkout@v4

src/validators/url.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,9 @@ fn check_sub_defaults(
544544
error: e.to_string(),
545545
context: None,
546546
};
547-
if let Some(ref default_host) = default_host {
548-
if !url.url().has_host() {
547+
548+
if !url.url().has_host() {
549+
if let Some(ref default_host) = default_host {
549550
url.url_mut().set_host(Some(default_host)).map_err(map_parse_err)?;
550551
} else if host_required {
551552
return Err(ErrorType::UrlParsing {

tests/validators/test_url.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ def test_url_defaults_single_url(validator_kwargs, url, expected):
287287
url_test_case_helper(url, expected, SCHEMA_VALIDATOR_MODE, s)
288288

289289

290+
def test_url_host_required():
291+
s = SchemaValidator(core_schema.url_schema(host_required=True))
292+
url_test_case_helper('test:', Err('empty host'), SCHEMA_VALIDATOR_MODE, s)
293+
url_test_case_helper('sftp://', Err('empty host'), SCHEMA_VALIDATOR_MODE, s)
294+
295+
290296
@pytest.mark.parametrize(
291297
'validator_kwargs,url,expected',
292298
[

0 commit comments

Comments
 (0)