Fix HTML entity rendering in file comments sidebar

Signed-off-by: Christopher Ng <chrng8@gmail.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
This commit is contained in:
Christopher Ng 2021-10-04 21:13:22 +00:00 committed by Carl Schwan
parent 18e32104ce
commit e5873a2f8d
No known key found for this signature in database
GPG key ID: 06B35D38387B67BE
3 changed files with 51 additions and 34 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -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
}