Skip to content

Commit

Permalink
Change valid URL check regular expression to validator library
Browse files Browse the repository at this point in the history
  • Loading branch information
choidabom committed Sep 5, 2024
1 parent 485d3af commit 4d3b2e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/utils/urlHyperlinkInserter.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down

0 comments on commit 4d3b2e4

Please sign in to comment.