Skip to content

Commit

Permalink
ponyfill URL.canParse (bluesky-social#2835)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben authored Sep 27, 2024
1 parent 2676206 commit eb20ff6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lemon-bags-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/common-web": patch
---

ponyfill URL.canParse
14 changes: 13 additions & 1 deletion packages/common-web/src/did-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,25 @@ const validateUrl = (urlStr: string): string | undefined => {
return undefined
}

if (!URL.canParse(urlStr)) {
if (!canParseUrl(urlStr)) {
return undefined
}

return urlStr
}

const canParseUrl =
URL.canParse ??
// URL.canParse is not available in Node.js < 18.17.0
((urlStr: string): boolean => {
try {
new URL(urlStr)
return true
} catch {
return false
}
})

// Types
// --------

Expand Down

0 comments on commit eb20ff6

Please sign in to comment.