Skip to content

Commit

Permalink
Encode URLs before saving them.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Jan 26, 2023
1 parent bdb843c commit 9c90186
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions web/components/bookmark/bookmark-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ export const bookmarkEdit = Component(({

const form = formRef.current

const url = form.url.value
let url = form.url.value
try {
url = (new URL(form.url.value)).toString()
} catch (err) {
console.warn(err)
console.warn('Error sanitizing URL')
}
const title = form.title.value
const note = form.note.value
const rawTags = form.tags.value
Expand All @@ -63,7 +69,14 @@ export const bookmarkEdit = Component(({
let archive_urls = []

for (const i of Object.keys(archiveURLs)) {
archive_urls.push(form[`archive-url-${i}`].value)
let archiveURL = form[`archive-url-${i}`].value
try {
archiveURL = (new URL(archiveURL)).toString()
} catch (err) {
console.warn(err)
console.warn('Error sanitizing archive url')
}
archive_urls.push(archiveURL)
}

archive_urls = archive_urls.filter(v => !!v && validateURL(v)).map(url => url.trim())
Expand Down

0 comments on commit 9c90186

Please sign in to comment.