Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dotCMS/src/main/java/com/dotmarketing/util/UtilMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,8 @@ public static String espaceForVelocity(String text) {

public static String escapeHTMLCodeFromJSON(String json) {
json = json.replace(":",":")
.replace(",",",");
.replace(",",",")
.replace("$","$");
return json;
}

Expand Down
18 changes: 18 additions & 0 deletions dotCMS/src/test/java/com/dotmarketing/util/UtilMethodsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,22 @@ public void test_base64Decode_invalidBase64String() {
final String invalidBase64 = "This is not a valid base64 string!";
UtilMethods.base64Decode(invalidBase64);
}

/**
* Method to test: {@link UtilMethods#escapeHTMLCodeFromJSON(String)}
* Given Scenario: A contentlet JSON value (e.g. a Story Block field) where {@code $}, {@code :} and
* {@code ,} have been stored as their decimal HTML numeric entities.
* Expected Result: The entities are decoded back to the literal characters so consumers such as the
* Block Editor display {@code $50} instead of {@code $50} (issue #35782).
*/
@Test
public void test_escapeHTMLCodeFromJSON_decodes_dollar_colon_and_comma() {
final String encoded = "{\"text\":\"The application fee is $50, see http://x.com\"}";
final String decoded = UtilMethods.escapeHTMLCodeFromJSON(encoded);

assertEquals("{\"text\":\"The application fee is $50, see http://x.com\"}", decoded);
assertFalse(decoded.contains("$"));
assertFalse(decoded.contains(":"));
assertFalse(decoded.contains(","));
}
}
Loading