Skip to content

Commit 91e7fcf

Browse files
dcousensemmatown
andauthored
Use new URL rather than encodeURI for document field validation (#9613)
Co-authored-by: Daniel Cousens <[email protected]> Co-authored-by: Emma Hamilton <[email protected]>
1 parent 83ea9fa commit 91e7fcf

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.changeset/fix-document-uris.mx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@keystone-6/fields-document": patch
3+
---
4+
5+
Use `new URL` rather than `encodeURI` for encoding URLs safely
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { sanitizeUrl } from '@braintree/sanitize-url'
22

33
export function isValidURL(url: string) {
4-
return url === sanitizeUrl(url) || url === encodeURI(sanitizeUrl(url))
4+
return (
5+
url === sanitizeUrl(url) ||
6+
new URL(url, 'https://a').toString() === new URL(sanitizeUrl(url), 'https://a').toString()
7+
)
58
}

0 commit comments

Comments
 (0)