Skip to content

Commit

Permalink
Merge pull request #1698 from floccusaddon/fix/htmlentities
Browse files Browse the repository at this point in the history
fix: Encode unsafe characters as HTML entities
  • Loading branch information
marcelklehr authored Aug 18, 2024
2 parents 8161425 + f82cdc1 commit 35191ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/lib/serializers/Html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ class HtmlSerializer implements Serializer {
return `<DL><p>\n${this._serializeFolder(folder, '')}</DL><p>\n`
}

_htmlentities_encode(string) {
return string.replace(/[\u00A0-\u9999<>&"]/g, char => '&#' + char.charCodeAt(0) + ';')
}

_serializeFolder(folder, indent) {
return folder.children
.map(child => {
if (child instanceof Bookmark) {
return (
`${indent}<DT><A HREF="${child.url}" TAGS="${''}" ID="${child.id}">${child.title}</A>\n`
`${indent}<DT><A HREF="${this._htmlentities_encode(child.url)}" TAGS="${''}" ID="${child.id}">${this._htmlentities_encode(child.title)}</A>\n`
)
} else if (child instanceof Folder) {
const nextIndent = indent + ' '
return (
`${indent}<DT><H3 ID="${child.id}">${child.title}</H3>\n` +
`${indent}<DT><H3 ID="${child.id}">${this._htmlentities_encode(child.title)}</H3>\n` +
`${indent}<DL><p>\n${this._serializeFolder(
child,
nextIndent
Expand Down
4 changes: 2 additions & 2 deletions src/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ describe('Floccus', function() {
parentId: localRoot
})
const barFolder = await browser.bookmarks.create({
title: "bar=?*'Ä_:-^;",
title: "bar=?*'Ä_:-^;<script>",
parentId: fooFolder.id
})
const bookmark = await browser.bookmarks.create({
Expand All @@ -1129,7 +1129,7 @@ describe('Floccus', function() {
title: 'foo!"§$%&/()=?"',
children: [
new Folder({
title: "bar=?*'Ä_:-^;",
title: "bar=?*'Ä_:-^;<script>",
children: [
new Bookmark({
title: 'url|!"=)/§_:;Ä\'*ü"',
Expand Down

0 comments on commit 35191ba

Please sign in to comment.