Skip to content
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

Modify URL validation to accept non-ASCII characters #57

Merged
merged 1 commit into from
Apr 17, 2019

Conversation

ul8
Copy link

@ul8 ul8 commented Apr 15, 2019

Domains containing non-ASCII characters are rejected in the URL validator

if (!filter_var($value, FILTER_VALIDATE_URL)) {

As the docs for FILTER_VALIDATE_URL state:

The function will only find ASCII URLs to be valid; internationalized domain names (containing non-ASCII characters) will fail.

I'm passing the url first through idn_to_ascii() to convert to a punycode url

https://www.php.net/manual/en/function.idn-to-ascii.php

So as an example, a domain such as http://www.tästdomäin.de will now be valid as it is internally first converted to http://www.xn--tstdomin-0zaf.de before validation.

The URL is finally still saved to DB in the original form including the Unicode chars, which is not valid by itself in browsers as a link. Users of the plugin thus must take care themselves to convert that as needed and write the punycode URL to href="" attributes, for example.

@sebastian-lenz sebastian-lenz merged commit e8ff7aa into sebastian-lenz:master Apr 17, 2019
@sebastian-lenz
Copy link
Owner

Great, thanks for sharing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants