Skip to content

Commit

Permalink
international_domain -> punycode_domain
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Nov 2, 2022
1 parent 7dd1608 commit b74eb11
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pydantic_core/_pydantic_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Url:
username: 'str | None'
password: 'str | None'
host: 'str | None'
host_type: Literal['domain', 'international_domain', 'ipv4', 'ipv6', None]
host_type: Literal['domain', 'punycode_domain', 'ipv4', 'ipv6', None]
port: 'int | None'
path: 'str | None'
query: 'str | None'
Expand Down
2 changes: 1 addition & 1 deletion src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl PyUrl {
#[getter]
pub fn host_type(&self) -> Option<&'static str> {
match self.lib_url.host() {
Some(url::Host::Domain(domain)) if domain.starts_with("xn--") => Some("international_domain"),
Some(url::Host::Domain(domain)) if domain.starts_with("xn--") => Some("punycode_domain"),
Some(url::Host::Domain(_)) => Some("domain"),
Some(url::Host::Ipv4(_)) => Some("ipv4"),
Some(url::Host::Ipv6(_)) => Some("ipv6"),
Expand Down
7 changes: 4 additions & 3 deletions tests/validators/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def test_url_error(py_and_json: PyAndJson, url, error):
('http://example.com', 'http://example.com/', 'domain'),
# works since we're in lax mode
(b'http://example.com', 'http://example.com/', 'domain'),
('https://£££.com', 'https://xn--9aaa.com/', 'international_domain'),
('https://xn--9aaa.com/', 'https://xn--9aaa.com/', 'international_domain'),
('http://à.א̈.com', 'http://xn--0ca.xn--ssa73l.com/', 'international_domain'),
('https://£££.com', 'https://xn--9aaa.com/', 'punycode_domain'),
('https://xn--9aaa.com/', 'https://xn--9aaa.com/', 'punycode_domain'),
('https://münchen/', 'https://xn--mnchen-3ya/', 'punycode_domain'),
('http://à.א̈.com', 'http://xn--0ca.xn--ssa73l.com/', 'punycode_domain'),
('ftp://127.0.0.1', 'ftp://127.0.0.1/', 'ipv4'),
('wss://1.1.1.1', 'wss://1.1.1.1/', 'ipv4'),
('ftp://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]', 'ftp://[2001:db8:85a3::8a2e:370:7334]/', 'ipv6'),
Expand Down

0 comments on commit b74eb11

Please sign in to comment.