mraible commented on code in PR #353:
URL: https://github.com/apache/roller/pull/353#discussion_r4637222318
##########
app/src/main/java/org/apache/roller/weblogger/pojos/wrapper/UserWrapper.java:
##########
@@ -53,19 +53,36 @@ public static UserWrapper wrap(User toWrap) {
*/
public String getUserName() {
if (WebloggerConfig.getBooleanProperty("user.hideUserNames")) {
- return this.pojo.getScreenName();
+ return getScreenName();
}
return this.pojo.getUserName();
}
+ /**
+ * Get the screen name as html escaped text, since users choose their own
+ * screen names and templates print them as they are.
+ */
public String getScreenName() {
- return HTMLSanitizer.conditionallySanitize(this.pojo.getScreenName());
+ return escapeOnce(this.pojo.getScreenName());
}
+ /**
+ * Get the full name as html escaped text.
+ */
public String getFullName() {
- return HTMLSanitizer.conditionallySanitize(this.pojo.getFullName());
+ return escapeOnce(this.pojo.getFullName());
+ }
+
+
+ /**
+ * Names are stored as typed when weblog admins are trusted, and already
+ * html encoded by the sanitizer when they aren't, so decode any entities
+ * before escaping to encode them exactly once.
+ */
+ private static String escapeOnce(String name) {
+ return
StringEscapeUtils.escapeHtml4(StringEscapeUtils.unescapeHtml4(name));
Review Comment:
Neither setting ever stores an ampersand encoded (the sanitizer only encodes
`<`, `>`, `"`, `'` and, with jsoup in #356, non-breaking spaces), so
`UserWrapper` now decodes just those entities, and only when
`weblogAdminsUntrusted` is true; trusted admins' names are escaped as stored,
and `Tom & Jerry` shows as typed either way. Media file authors in
`feeds.vm` now go through the same wrapper (`$utils.wrapUser($file.creator)`)
instead of decoding the raw name.
`UserWrapperTest.typedEntitiesAreShownAsTyped` and
`FeedAuthorEscapingTest.trustedAdminNamesAreText` (plus a `Tom & Jerry` row
in the untrusted feed cases) fail on the previous head and pass now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]