diff --git a/dotCMS/hotfix_tracking.md b/dotCMS/hotfix_tracking.md index 2fa3a6b89680..ea412045035f 100644 --- a/dotCMS/hotfix_tracking.md +++ b/dotCMS/hotfix_tracking.md @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/dotCMS/src/integration-test/java/com/dotmarketing/portlets/contentlet/transform/ContentletTransformerTest.java b/dotCMS/src/integration-test/java/com/dotmarketing/portlets/contentlet/transform/ContentletTransformerTest.java index e291d5a67393..b68c1490cfa2 100644 --- a/dotCMS/src/integration-test/java/com/dotmarketing/portlets/contentlet/transform/ContentletTransformerTest.java +++ b/dotCMS/src/integration-test/java/com/dotmarketing/portlets/contentlet/transform/ContentletTransformerTest.java @@ -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 keyValueField = findContentlet.getKeyValueProperty("keyValueField"); + + Assert.assertFalse(keyValueField.get("origin").toString().contains(":")); + Assert.assertFalse(keyValueField.get("origin").toString().contains(",")); + + } + /** * Utitlity method to validate a string date against the ISO8601 format * @param dateString diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/transform/ContentletTransformer.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/transform/ContentletTransformer.java index 69351ce70697..204da8bd0c16 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/transform/ContentletTransformer.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/transform/ContentletTransformer.java @@ -89,7 +89,8 @@ private static Contentlet transform(final Map 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()); diff --git a/dotCMS/src/main/java/com/dotmarketing/util/UtilMethods.java b/dotCMS/src/main/java/com/dotmarketing/util/UtilMethods.java index ba99f4195e59..d6858886a12b 100644 --- a/dotCMS/src/main/java/com/dotmarketing/util/UtilMethods.java +++ b/dotCMS/src/main/java/com/dotmarketing/util/UtilMethods.java @@ -1389,7 +1389,11 @@ public static String espaceForVelocity(String text) { return ""; } - + public static String escapeHTMLCodeFromJSON(String json) { + json = json.replace(":",":") + .replace(",",","); + return json; + } // Used by the code generated in the contentletmapservices public static String evaluateVelocity(String vtl, Context ctx) {