Skip to content

Commit eb20ff6

Browse files
ponyfill URL.canParse (#2835)
1 parent 2676206 commit eb20ff6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

.changeset/lemon-bags-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@atproto/common-web": patch
3+
---
4+
5+
ponyfill URL.canParse

packages/common-web/src/did-doc.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,25 @@ const validateUrl = (urlStr: string): string | undefined => {
145145
return undefined
146146
}
147147

148-
if (!URL.canParse(urlStr)) {
148+
if (!canParseUrl(urlStr)) {
149149
return undefined
150150
}
151151

152152
return urlStr
153153
}
154154

155+
const canParseUrl =
156+
URL.canParse ??
157+
// URL.canParse is not available in Node.js < 18.17.0
158+
((urlStr: string): boolean => {
159+
try {
160+
new URL(urlStr)
161+
return true
162+
} catch {
163+
return false
164+
}
165+
})
166+
155167
// Types
156168
// --------
157169

0 commit comments

Comments
 (0)