diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index 796d44994..6bb94fc1c 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -11,7 +11,7 @@ on: jobs: benchmarks: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 diff --git a/src/validators/url.rs b/src/validators/url.rs index 634d1ce43..46bab20c1 100644 --- a/src/validators/url.rs +++ b/src/validators/url.rs @@ -544,8 +544,9 @@ fn check_sub_defaults( error: e.to_string(), context: None, }; - if let Some(ref default_host) = default_host { - if !url.url().has_host() { + + if !url.url().has_host() { + if let Some(ref default_host) = default_host { url.url_mut().set_host(Some(default_host)).map_err(map_parse_err)?; } else if host_required { return Err(ErrorType::UrlParsing { diff --git a/tests/validators/test_url.py b/tests/validators/test_url.py index 1c349885e..59489dd00 100644 --- a/tests/validators/test_url.py +++ b/tests/validators/test_url.py @@ -287,6 +287,12 @@ def test_url_defaults_single_url(validator_kwargs, url, expected): url_test_case_helper(url, expected, SCHEMA_VALIDATOR_MODE, s) +def test_url_host_required(): + s = SchemaValidator(core_schema.url_schema(host_required=True)) + url_test_case_helper('test:', Err('empty host'), SCHEMA_VALIDATOR_MODE, s) + url_test_case_helper('sftp://', Err('empty host'), SCHEMA_VALIDATOR_MODE, s) + + @pytest.mark.parametrize( 'validator_kwargs,url,expected', [