Skip to content

Commit

Permalink
#25903 include in 23.10.24
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed May 1, 2024
1 parent f4be26c commit 8fe638b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dotCMS/hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ This maintenance release includes the following code fixes:
88. https://github.com/dotCMS/core/issues/27563 : Site or Folder field does not show on the relate content window #27563
89. https://github.com/dotCMS/core/issues/27878 : System Table Blocks on Load #27878
90. https://github.com/dotCMS/core/issues/27361 : CSV Content import cannot process host or folder information #27361
91. https://github.com/dotCMS/core/issues/26582 : [Site Browser] : Open folders get collapsed after moving away from portlet #26582
91. https://github.com/dotCMS/core/issues/26582 : [Site Browser] : Open folders get collapsed after moving away from portlet #26582
92. https://github.com/dotCMS/core/issues/25903 : Key/Value field escaping colon and comma characters to HTML encoded version. #25903
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,32 @@ public void Transformer_content_Resource_Date_Formats_Test()

}

/**
* Given Scenario: This tests that the transformer used to transform content from the DB decode colons and commas
* Expected Result: Colons and commas shouldn't be HTML encoded when transform them from the DB.
* @throws DotDataException
* @throws DotSecurityException
*/
@Test
public void Transformer_content_Decode_JSON()
throws Exception {

final ContentType contentType = TestDataUtils.newContentTypeFieldTypesGalore();
final ContentletDataGen contentletDataGen = new ContentletDataGen(contentType.inode())
.setProperty("title", "test_KeyValueFieldDecode" + System.currentTimeMillis())
.setProperty("keyValueField", "{\"origin\":\"https://test.com , http://test2.com\"}");

final Contentlet contentlet = contentletDataGen.nextPersisted();

final Contentlet findContentlet = APILocator.getContentletAPI().find(contentlet.getInode(),APILocator.systemUser(),false);

final Map<String, Object> keyValueField = findContentlet.getKeyValueProperty("keyValueField");

Assert.assertFalse(keyValueField.get("origin").toString().contains("&#58;"));
Assert.assertFalse(keyValueField.get("origin").toString().contains("&#44;"));

}

/**
* Utitlity method to validate a string date against the ISO8601 format
* @param dateString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ private static Contentlet transform(final Map<String, Object> map) {
final boolean hasJsonFields = (contentletJsonAPI.isPersistContentAsJson() && UtilMethods.isSet(map.get(ContentletJsonAPI.CONTENTLET_AS_JSON)));
if(hasJsonFields){
try {
final String json = map.get(ContentletJsonAPI.CONTENTLET_AS_JSON).toString();
String json = map.get(ContentletJsonAPI.CONTENTLET_AS_JSON).toString();
json = UtilMethods.escapeHTMLCodeFromJSON(json);//Escape HTML chars from JSON
contentlet = contentletJsonAPI.mapContentletFieldsFromJson(json);
}catch (Exception e){
final String errorMsg = String.format("Unable to populate contentlet from json for ID='%s', Inode='%s', Content-Type '%s': %s", contentletId, inode, contentTypeId, e.getMessage());
Expand Down
6 changes: 5 additions & 1 deletion dotCMS/src/main/java/com/dotmarketing/util/UtilMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,11 @@ public static String espaceForVelocity(String text) {
return "";
}


public static String escapeHTMLCodeFromJSON(String json) {
json = json.replace("&#58;",":")
.replace("&#44;",",");
return json;
}

// Used by the code generated in the contentletmapservices
public static String evaluateVelocity(String vtl, Context ctx) {
Expand Down

0 comments on commit 8fe638b

Please sign in to comment.