Skip to content

Add encoded_string() method to the URL types #11580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 19, 2025

Conversation

YassinNouh21
Copy link
Contributor

@YassinNouh21 YassinNouh21 commented Mar 18, 2025

Change Summary

This PR introduces a new encoded property to the Url class in pydantic/networks.py. The encoded property returns the punycode-encoded host version of the URL as a string. Additionally, a new test case has been added to tests/test_networks.py to verify the functionality of the encoded property.

Related issue number

fixes #11551

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog

  • Unit tests for the changes exist

  • Tests pass on CI

  • Documentation reflects the changes where applicable

  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Copy link

codspeed-hq bot commented Mar 18, 2025

CodSpeed Performance Report

Merging #11580 will not alter performance

Comparing YassinNouh21:feature/11551-encoded-url-property (3f67a86) with main (a2846da)

Summary

✅ 46 untouched benchmarks

Copy link
Contributor

github-actions bot commented Mar 19, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  networks.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Member

@Viicos Viicos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. The encoded() method needs to be added on _BaseMultiHostUrl as well.

@@ -330,6 +330,7 @@ class Model(BaseModel):
# https://www.xudongz.com/blog/2017/idn-phishing/ accepted but converted
('https://www.аррӏе.com/', 'https://www.xn--80ak6aa92e.com/'),
('https://exampl£e.org', 'https://xn--example-gia.org/'),
('http://puny£code.com', 'http://xn--punycode-eja.com/'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
('http://puny£code.com', 'http://xn--punycode-eja.com/'),

@YassinNouh21
Copy link
Contributor Author

@Viicos can u take a look on the new _BaseMultiHostUrl test that I have added

@Viicos Viicos changed the title feat(url): add encoded property returning punycode-encoded host string Add encoded_string() method to the URL types Mar 19, 2025
Copy link
Member

@Viicos Viicos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution

@Viicos Viicos merged commit 87cb27f into pydantic:main Mar 19, 2025
60 checks passed
@YassinNouh21 YassinNouh21 deleted the feature/11551-encoded-url-property branch March 19, 2025 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BaseUrl: Provide a property or method to access the encoded URL string.
2 participants