Skip to content

Commit

Permalink
Merge pull request #162 from tunapanda/fix/url-validation-regex
Browse files Browse the repository at this point in the history
fix: improve url regex validations
  • Loading branch information
Murage authored Dec 4, 2024
2 parents 16b1215 + b428bb7 commit bd50193
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"webpack-merge": "^5.8.0"
},
"scripts": {
"preinstall": "npx only-allow yarn",
"watch": "webpack --watch --config webpack.dev.js",
"start": "webpack-dev-server --mode development --config webpack.dev.js",
"build:dev": "webpack --mode development --config webpack.dev.js",
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export function urlPath(path: string): string {
path = path.trim();

//regex to check if is an absolute url (with *a* protocol) or a valid URI
const urlRegex = /^([a-z0-9]+:\/\/|www.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i;
const urlRegex = /^(https?:\/\/)?([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*|localhost)(:\d{1,5})?(\/[^\s]*)?$/i

if (path.match(urlRegex)) {
return path;
Expand Down

0 comments on commit bd50193

Please sign in to comment.