Skip to content

Commit

Permalink
Merge pull request #29599 from nextcloud/backport/29029/stable21
Browse files Browse the repository at this point in the history
[stable21] Fix HTML entity rendering in file comments sidebar
  • Loading branch information
artonge authored Nov 9, 2021
2 parents e3dd022 + 344e850 commit ad50457
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/comments/js/comments-app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/comments/js/comments-app.js.map

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion apps/comments/src/services/GetComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ function processMultistatus(result, isDetailed = false) {
const {
propstat: { prop: props },
} = item
return prepareFileFromProps(props, props.id.toString(), isDetailed)
// Decode HTML entities
const decodedProps = {
...props,
// Decode twice to handle potentially double-encoded entities
// FIXME Remove this once https://github.com/nextcloud/server/issues/29306 is resolved
actorDisplayName: decodeHtmlEntities(props.actorDisplayName, 2),
message: decodeHtmlEntities(props.message, 2),
}
return prepareFileFromProps(decodedProps, decodedProps.id.toString(), isDetailed)
})
}

function decodeHtmlEntities(value, passes = 1) {
const parser = new DOMParser()
let decoded = value
for (let i = 0; i < passes; i++) {
decoded = parser.parseFromString(decoded, 'text/html').documentElement.textContent
}
return decoded
}

0 comments on commit ad50457

Please sign in to comment.