-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix(entity-link): more robust url regex #933
Conversation
This reverts commit 2c9f15f1beeb33b1b0fea299aaff0a2b528cf416.
packages/entities/entities-shared/src/composables/useExternalLinkCreator.ts
Outdated
Show resolved
Hide resolved
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g // eslint-disable-line no-useless-escape | ||
// Test validity of generated URL; only allows `http` protocal if domain is `localhost` | ||
/* eslint-disable-next-line no-useless-escape */ | ||
const validUrlRegex = /^(https:\/\/(www\.)?([a-zA-Z0-9-]+\.){1,}[a-zA-Z]{2,}(:[0-9]+)?(\/[^\/]+)*)$|^(https|http):\/\/localhost(:[0-9]+)?(\/[^\/]+)*$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add a unit test for this composable to test happy and bad paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call - pushed a commit with a few more passing + failing cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, defer to @hfukada for final
Summary
URL regex should allow dev preview URLs / .tech / .com domains, but also
localhost
withhttp
protocol, followedPR Checklist