Skip to content

Commit 799838a

Browse files
authored
Merge pull request #35102 from nextcloud/backport/35054/stable23-fix-html-entities-not-decoded-in-comment-just-added
[stable23] Fix HTML entities not decoded in comment just added
2 parents 3346288 + 296aafe commit 799838a

File tree

5 files changed

+75
-24
lines changed

5 files changed

+75
-24
lines changed

apps/comments/js/comments-app.js

Lines changed: 35 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/comments/js/comments-app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/comments/src/services/GetComments.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import { parseXML, prepareFileFromProps } from 'webdav/dist/node/tools/dav'
2424
import { processResponsePayload } from 'webdav/dist/node/response'
25+
import { decodeHtmlEntities } from '../utils/decodeHtmlEntities'
2526
import client from './DavClient'
2627

2728
export const DEFAULT_LIMIT = 20
@@ -85,12 +86,3 @@ function processMultistatus(result, isDetailed = false) {
8586
return prepareFileFromProps(decodedProps, decodedProps.id.toString(), isDetailed)
8687
})
8788
}
88-
89-
function decodeHtmlEntities(value, passes = 1) {
90-
const parser = new DOMParser()
91-
let decoded = value
92-
for (let i = 0; i < passes; i++) {
93-
decoded = parser.parseFromString(decoded, 'text/html').documentElement.textContent
94-
}
95-
return decoded
96-
}

apps/comments/src/services/NewComment.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import { getCurrentUser } from '@nextcloud/auth'
2424
import { getRootPath } from '../utils/davUtils'
25+
import { decodeHtmlEntities } from '../utils/decodeHtmlEntities'
2526
import axios from '@nextcloud/axios'
2627
import client from './DavClient'
2728

@@ -55,5 +56,12 @@ export default async function(commentsType, ressourceId, message) {
5556
details: true,
5657
})
5758

59+
const props = comment.data.props
60+
// Decode twice to handle potentially double-encoded entities
61+
// FIXME Remove this once https://github.com/nextcloud/server/issues/29306
62+
// is resolved
63+
props.actorDisplayName = decodeHtmlEntities(props.actorDisplayName, 2)
64+
props.message = decodeHtmlEntities(props.message, 2)
65+
5866
return comment.data
5967
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @copyright Copyright (c) 2021 Christopher Ng <chrng8@gmail.com>
3+
*
4+
* @author Christopher Ng <chrng8@gmail.com>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
export function decodeHtmlEntities(value, passes = 1) {
24+
const parser = new DOMParser()
25+
let decoded = value
26+
for (let i = 0; i < passes; i++) {
27+
decoded = parser.parseFromString(decoded, 'text/html').documentElement.textContent
28+
}
29+
return decoded
30+
}

0 commit comments

Comments
 (0)