diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 10bf09b9..a22e145d 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -74,6 +74,7 @@ "@types/react-dom": "^18.2.17", "@types/react-infinite-scroller": "^1.2.5", "@types/react-scroll-sync": "^0.9.0", + "@types/validator": "^13.12.1", "@typescript-eslint/eslint-plugin": "^6.14.0", "@typescript-eslint/parser": "^6.14.0", "@vitejs/plugin-react": "^4.2.1", @@ -2804,6 +2805,12 @@ "integrity": "sha512-EwmlvuaxPNej9+T4v5AuBPJa2x2UOJVdjCtDHgcDqitUeOtjnJKJ+apYjVcAoBEMjKW1VVFGZLUb5+qqa09XFA==", "license": "MIT" }, + "node_modules/@types/validator": { + "version": "13.12.1", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.12.1.tgz", + "integrity": "sha512-w0URwf7BQb0rD/EuiG12KP0bailHKHP5YVviJG9zw3ykAokL0TuxU2TUqMB7EwZ59bDHYdeTIvjI5m0S7qHfOA==", + "dev": true + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "6.21.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.21.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index ba84ecd4..dd0c6a5b 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -87,6 +87,7 @@ "@types/react-dom": "^18.2.17", "@types/react-infinite-scroller": "^1.2.5", "@types/react-scroll-sync": "^0.9.0", + "@types/validator": "^13.12.1", "@typescript-eslint/eslint-plugin": "^6.14.0", "@typescript-eslint/parser": "^6.14.0", "@vitejs/plugin-react": "^4.2.1", diff --git a/frontend/src/utils/urlHyperlinkInserter.ts b/frontend/src/utils/urlHyperlinkInserter.ts index 60f32c2c..961f29b6 100644 --- a/frontend/src/utils/urlHyperlinkInserter.ts +++ b/frontend/src/utils/urlHyperlinkInserter.ts @@ -1,10 +1,9 @@ import { EditorView } from "codemirror"; +import validator from "validator"; import { CodePairDocType } from "../store/editorSlice"; const isValidUrl = (url: string) => { - // eslint-disable-next-line no-useless-escape - const urlRegex = /^(https?|ftp):\/\/(-\.)?([^\s\/?\.#-]+\.?)+(\/[^\s]*)?$/i; - return urlRegex.test(url); + return validator.isURL(url); }; const insertLinkToEditor = (url: string, view: EditorView, doc: CodePairDocType) => {