Skip to content

Conversation

@chucker
Copy link
Owner

@chucker chucker commented Oct 16, 2023

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

@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.

4 participants