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

allow domain names in urls not starting with www #50

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pages/txt-generator.jsx
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ const removeIndex = (array, index) => [
]

const urlRegex = new RegExp(
/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/
/(https?:\/\/(?:\.|(?!))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:\.|(?!))[a-zA-Z0-9]+\.[^\s]{2,}|\.[a-zA-Z0-9]+\.[^\s]{2,})/
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that you may need to remove the \. that appeared after the www portions. Currently, a URL like http://.example.org/mrf.json will pass validation, but http://example.org/mrf.json will fail. Additionally, the expression should enforce a full string match with ^ at the start and $ at the end. Otherwise, a typo like htps://example-hospital.com could slip through.

I know you mentioned that you couldn't get the valid-url package to do what you wanted, but I think trying to build up a huge regex like this is going to be hard to test. What about it wasn't working well?

)

const TxtGenerator = () => {