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

add more edge cases for URLs #166

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

chucker
Copy link
Owner

@chucker chucker commented Oct 16, 2023

  • '+' in the path
  • '@' for user names

Sören Kuklau added 2 commits October 16, 2023 10:31
@chucker chucker requested a review from ricardoboss October 18, 2023 20:11
"(?<port>\\d+))?(?<path>/[^#?]*)?(?<query>\\?"
"((?<userColon>:)(?<password>\\w+))?(?<at>@))?"
"(?<host>[^:/]+)((?<portColon>:)(?<port>\\d+))?"
"(?<path>/[^#?]*)?(?<query>\\?"
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the @ symbol is on its own (which is allowed by this regex), it is included in the host:
image

Is this intended?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

@ricardoboss ricardoboss Oct 18, 2023

Choose a reason for hiding this comment

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

This (?<host>[^:\/]+) implicitly allows any characters. Maybe this should be constrained to alphanumerics (i.e. (?<host>[a-zA-Z0-9-.]+))?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I believe this doesn’t matter, because the host is later on (in the loop) restricted to [NSCharacterSet URLHostAllowedCharacterSet].

Copy link
Owner Author

Choose a reason for hiding this comment

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

Link to test

I've made the user group optional in the regex, and if not set, 8e32b64 will now remove the @ altogether. Added another test for this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

image

you may want to make group 3 a non-capturing group

Copy link
Collaborator

Choose a reason for hiding this comment

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

i.e. this one
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have used this one in one of my projects, in case you want to look at another approach: https://regex101.com/r/bsN8uj/5

@chucker
Copy link
Owner Author

chucker commented Oct 19, 2023

Hmm, what about IDNs? Sigh.

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