Skip to content

Commit

Permalink
fix: some invalid url wrongly detected by anchorme (#3186)
Browse files Browse the repository at this point in the history
* fix: some invalid url wrongly detected by anchorme

url like `https://…a.com`. see alexcorvi/anchorme.js/issues/109

closes #3185

* Update packages/shared/src/utils/parseURL.ts

Co-authored-by: Jack Works <[email protected]>

Co-authored-by: Jack Works <[email protected]>
  • Loading branch information
UncleBill and Jack-Works authored May 17, 2021
1 parent 7290b73 commit ad6a8bf
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/shared/src/utils/parseURL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import parser from 'anchorme'
export function parseURL(string: string) {
return parser.list(string).map((x) => x.string)
export function parseURL(text: string) {
return parser
.list(text)
.map((x) => x.string)
.filter((y) => {
// See https://github.com/alexcorvi/anchorme.js/issues/109
try {
new URL(y)
return true
} catch {
return false
}
})
}

0 comments on commit ad6a8bf

Please sign in to comment.