diff --git a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/TeaserImpl.java b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/TeaserImpl.java index 390be976e0..dccac05492 100644 --- a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/TeaserImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/TeaserImpl.java @@ -56,6 +56,7 @@ import com.day.cq.wcm.api.PageManager; import com.day.cq.wcm.api.components.Component; import com.day.cq.wcm.api.designer.Style; +import com.day.text.Text; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @@ -366,7 +367,12 @@ public boolean isTitleLinkHidden() { public String getDescription() { if (this.description == null && !this.descriptionHidden) { if (this.descriptionFromPage) { - this.description = this.getTargetPage().map(Page::getDescription).orElse(null); + this.description = this.getTargetPage() + .map(Page::getDescription) + // page properties uses a plain text field - which may contain special chars that need to be escaped in HTML + // because the resulting description from the teaser is expected to be HTML produced by the RTE editor + .map(Text::escapeXml) + .orElse(null); } else { this.description = this.resource.getValueMap().get(JcrConstants.JCR_DESCRIPTION, String.class); } diff --git a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/TeaserImplTest.java b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/TeaserImplTest.java index e02ff7ce42..5a33c4f2ba 100644 --- a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/TeaserImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v1/TeaserImplTest.java @@ -122,7 +122,8 @@ protected void testFullyConfiguredTeaserVanityPath() { protected void testPageInheritedProperties() { Teaser teaser = getTeaserUnderTest(TEASER_6); assertEquals("Teasers Test", teaser.getTitle()); - assertEquals("Teasers description", teaser.getDescription()); + // < and > are expected escaped, because the page properties provide only a plain text field for the page description + assertEquals("Teasers description from <page properties>", teaser.getDescription()); } @Test @@ -196,7 +197,8 @@ protected void testTeaserWithTitleAndDescriptionFromActions() { assertTrue(teaser.isActionsEnabled(), "Expected teaser with actions"); assertEquals(2, teaser.getActions().size(), "Expected to find two Actions"); assertEquals("Teasers Test", teaser.getTitle()); - assertEquals("Teasers description", teaser.getDescription()); + // < and > are expected escaped, because the page properties provide only a plain text field for the page description + assertEquals("Teasers description from <page properties>", teaser.getDescription()); Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser11")); } diff --git a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v2/TeaserImplTest.java b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v2/TeaserImplTest.java index 02941dd046..142e5b971a 100644 --- a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v2/TeaserImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/models/v2/TeaserImplTest.java @@ -50,7 +50,8 @@ protected void testTeaserWithTitleAndDescriptionFromActions() { assertTrue(teaser.isActionsEnabled(), "Expected teaser with actions"); assertEquals(2, teaser.getActions().size(), "Expected to find two Actions"); assertEquals("Teasers Test", teaser.getTitle()); - assertEquals("Teasers description", teaser.getDescription()); + // < and > are expected escaped, because the page properties provide only a plain text field for the page description + assertEquals("Teasers description from <page properties>", teaser.getDescription()); Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser11")); } diff --git a/bundles/core/src/test/resources/teaser/exporter-teaser11.json b/bundles/core/src/test/resources/teaser/exporter-teaser11.json index c11649a478..5cfbda05c4 100644 --- a/bundles/core/src/test/resources/teaser/exporter-teaser11.json +++ b/bundles/core/src/test/resources/teaser/exporter-teaser11.json @@ -1,6 +1,6 @@ { "title": "Teasers Test", - "description": "Teasers description", + "description": "Teasers description from <page properties>", "linkURL": "/core/content/teasers.html", "actionsEnabled": true, "imageLinkHidden": false, @@ -38,7 +38,7 @@ "dataLayer": { "teaser-84f85e5d32": { "xdm:linkURL": "/core/content/teasers.html", - "dc:description": "Teasers description", + "dc:description": "Teasers description from <page properties>", "@type": "core/wcm/components/teaser/v1/teaser", "dc:title": "Teasers Test" } diff --git a/bundles/core/src/test/resources/teaser/test-content.json b/bundles/core/src/test/resources/teaser/test-content.json index b32c030249..741e04d28f 100644 --- a/bundles/core/src/test/resources/teaser/test-content.json +++ b/bundles/core/src/test/resources/teaser/test-content.json @@ -5,7 +5,7 @@ "jcr:primaryType" : "cq:PageContent", "jcr:title" : "Teasers Test", "sling:resourceType": "core/wcm/components/page/v2/page", - "jcr:description" : "Teasers description", + "jcr:description" : "Teasers description from ", "root" : { "jcr:primaryType" : "nt:unstructured", "sling:resourceType": "wcm/foundation/components/responsivegrid", diff --git a/bundles/core/src/test/resources/teaser/v2/exporter-teaser11.json b/bundles/core/src/test/resources/teaser/v2/exporter-teaser11.json index 8359d7b640..39e56d47ac 100644 --- a/bundles/core/src/test/resources/teaser/v2/exporter-teaser11.json +++ b/bundles/core/src/test/resources/teaser/v2/exporter-teaser11.json @@ -1,6 +1,6 @@ { "title": "Teasers Test", - "description": "Teasers description", + "description": "Teasers description from <page properties>", "link": { "valid": true, "url": "/core/content/teasers.html" @@ -47,7 +47,7 @@ "dataLayer": { "teaser-84f85e5d32": { "xdm:linkURL": "/core/content/teasers.html", - "dc:description": "Teasers description", + "dc:description": "Teasers description from <page properties>", "@type": "core/wcm/components/teaser/v2/teaser", "dc:title": "Teasers Test" } diff --git a/bundles/core/src/test/resources/teaser/v2/test-content.json b/bundles/core/src/test/resources/teaser/v2/test-content.json index 6a55cfaa8c..d0fde73764 100644 --- a/bundles/core/src/test/resources/teaser/v2/test-content.json +++ b/bundles/core/src/test/resources/teaser/v2/test-content.json @@ -1,178 +1,272 @@ { - "teasers": { - "jcr:primaryType": "cq:Page", - "jcr:content" : { - "jcr:primaryType" : "cq:PageContent", - "jcr:title" : "Teasers Test", - "sling:resourceType": "core/wcm/components/page/v2/page", - "jcr:description" : "Teasers description", - "cq:featuredimage" : { - "jcr:primaryType" : "nt:unstructured", - "jcr:createdBy" : "admin", - "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png" - }, - "root" : { - "jcr:primaryType" : "nt:unstructured", - "sling:resourceType": "wcm/foundation/components/responsivegrid", - "responsivegrid" : { - "jcr:primaryType" : "nt:unstructured", - "sling:resourceType": "wcm/foundation/components/responsivegrid", - "teaser-1" : { - "jcr:primaryType" : "nt:unstructured", - "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", - "pretitle" : "Teaser's Pretitle", - "jcr:title" : "Teaser", - "jcr:description" : "Description", - "linkURL" : "https://www.adobe.com", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser" - }, - "teaser-2" : { - "jcr:primaryType" : "nt:unstructured", - "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark", - "jcr:title" : "Teaser", - "jcr:description" : "Description", - "linkURL" : "https://www.adobe.com", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser" - }, - "teaser-3" : { - "jcr:primaryType" : "nt:unstructured", - "jcr:title" : "Teaser", - "jcr:description" : "Description", - "linkURL" : "https://www.adobe.com", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser" - }, - "teaser-4" : { - "jcr:primaryType" : "nt:unstructured", - "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", - "jcr:title" : "Teaser", - "jcr:description" : "Description", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser" - }, - "teaser-5" : { - "jcr:primaryType" : "nt:unstructured", - "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", - "jcr:title" : "Teaser", - "jcr:description" : "Description", - "linkURL" : "/content/teasers", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser" - }, - "teaser-6" : { - "jcr:primaryType" : "nt:unstructured", - "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", - "linkURL" : "/content/teasers", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser", - "titleFromPage": true, - "descriptionFromPage": true - }, - "teaser-7" : { - "jcr:primaryType" : "nt:unstructured", - "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", - "linkURL" : "/content/teasers", - "jcr:title" : "Teaser", - "jcr:description" : "Description", - "actionsEnabled" : true, - "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", - "actions" : { - "jcr:primaryType" : "nt:unstructured", - "item0" : { - "jcr:primaryType" : "nt:unstructured", - "link": "http://www.adobe.com", - "text": "Adobe" - }, - "item1" : { - "jcr:primaryType" : "nt:unstructured", - "link": "/content/teasers", - "text": "Teasers" - } - } - }, - "teaser-8" : { - "jcr:primaryType" : "nt:unstructured", - "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", - "actionsEnabled" : true, - "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", - "titleFromPage": true, - "descriptionFromPage": true, - "actions" : { - "jcr:primaryType" : "nt:unstructured", - "item0" : { - "jcr:primaryType" : "nt:unstructured", - "link": "/content/teasers", - "text": "Teasers" - }, - "item1" : { - "jcr:primaryType" : "nt:unstructured", - "link": "http://www.adobe.com", - "text": "Adobe" - } + "teasers": { + "jcr:primaryType": "cq:Page", + "jcr:content" : { + "jcr:primaryType" : "cq:PageContent", + "jcr:title" : "Teasers Test", + "sling:resourceType": "core/wcm/components/page/v2/page", + "jcr:description" : "Teasers description from ", + "cq:featuredimage" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:createdBy" : "admin", + "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png" + }, + "root" : { + "jcr:primaryType" : "nt:unstructured", + "sling:resourceType": "wcm/foundation/components/responsivegrid", + "responsivegrid" : { + "jcr:primaryType" : "nt:unstructured", + "sling:resourceType": "wcm/foundation/components/responsivegrid", + "teaser-1" : { + "jcr:primaryType" : "nt:unstructured", + "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", + "pretitle" : "Teaser's Pretitle", + "jcr:title" : "Teaser", + "jcr:description" : "Description", + "linkURL" : "https://www.adobe.com", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-2" : { + "jcr:primaryType" : "nt:unstructured", + "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark", + "jcr:title" : "Teaser", + "jcr:description" : "Description", + "linkURL" : "https://www.adobe.com", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-3" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:title" : "Teaser", + "jcr:description" : "Description", + "linkURL" : "https://www.adobe.com", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-4" : { + "jcr:primaryType" : "nt:unstructured", + "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", + "jcr:title" : "Teaser", + "jcr:description" : "Description", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-5" : { + "jcr:primaryType" : "nt:unstructured", + "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", + "jcr:title" : "Teaser", + "jcr:description" : "Description", + "linkURL" : "/content/teasers", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-6" : { + "jcr:primaryType" : "nt:unstructured", + "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", + "linkURL" : "/content/teasers", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser", + "titleFromPage": true, + "descriptionFromPage": true + }, + "teaser-7" : { + "jcr:primaryType" : "nt:unstructured", + "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", + "linkURL" : "/content/teasers", + "jcr:title" : "Teaser", + "jcr:description" : "Description", + "actionsEnabled" : true, + "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", + "actions" : { + "jcr:primaryType" : "nt:unstructured", + "item0" : { + "jcr:primaryType" : "nt:unstructured", + "link": "http://www.adobe.com", + "text": "Adobe" + }, + "item1" : { + "jcr:primaryType" : "nt:unstructured", + "link": "/content/teasers", + "text": "Teasers" + } + } + }, + "teaser-8" : { + "jcr:primaryType" : "nt:unstructured", + "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", + "actionsEnabled" : true, + "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", + "titleFromPage": true, + "descriptionFromPage": true, + "actions" : { + "jcr:primaryType" : "nt:unstructured", + "item0" : { + "jcr:primaryType" : "nt:unstructured", + "link": "/content/teasers", + "text": "Teasers" + }, + "item1" : { + "jcr:primaryType" : "nt:unstructured", + "link": "http://www.adobe.com", + "text": "Adobe" + } - } - }, - "teaser-9" : { - "jcr:primaryType" : "nt:unstructured", - "jcr:title" : "Teaser", - "jcr:description" : "Description", - "linkURL" : "/content/teasers", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser" - }, - "teaser-10" : { - "jcr:primaryType" : "nt:unstructured", - "jcr:title" : "Teaser", - "jcr:description" : "Description", - "linkURL" : "/content/teasers", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser" - }, - "teaser-11" : { - "jcr:primaryType" : "nt:unstructured", - "jcr:title" : "Teaser", - "actionsEnabled" : true, - "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", - "actions" : { - "jcr:primaryType" : "nt:unstructured", - "item0" : { - "jcr:primaryType" : "nt:unstructured", - "link": "http://www.adobe.com", - "text": "Adobe" - }, - "item1" : { - "jcr:primaryType" : "nt:unstructured", - "link": "/content/teasers", - "text": "Teasers" - } - } - }, - "teaser-12" : { - "jcr:primaryType" : "nt:unstructured", - "jcr:title" : "Teaser", - "actionsEnabled" : true, - "titleFromPage" : true, - "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", - "actions" : { - "jcr:primaryType" : "nt:unstructured", - "item0" : { - "jcr:primaryType" : "nt:unstructured", - "link": "http://www.adobe.com", - "text": "Adobe" - } - } - }, - "teaser-13" : { - "jcr:primaryType" : "nt:unstructured", - "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", - "pretitle" : "Teaser's Pretitle", - "jcr:title" : "Teaser", - "jcr:description" : "Description", - "linkURL" : "https://www.adobe.com", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser", - "titleType" : "h4" - }, - "teaser-20" : { - "jcr:primaryType" : "nt:unstructured", - "linkURL" : "/content/teasers", - "sling:resourceType": "core/wcm/components/teaser/v2/teaser" - } - } } + }, + "teaser-9" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:title" : "Teaser", + "jcr:description" : "Description", + "linkURL" : "/content/teasers", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-10" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:title" : "Teaser", + "jcr:description" : "Description", + "linkURL" : "/content/teasers", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-11" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:title" : "Teaser", + "actionsEnabled" : true, + "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", + "actions" : { + "jcr:primaryType" : "nt:unstructured", + "item0" : { + "jcr:primaryType" : "nt:unstructured", + "link": "http://www.adobe.com", + "text": "Adobe" + }, + "item1" : { + "jcr:primaryType" : "nt:unstructured", + "link": "/content/teasers", + "text": "Teasers" + } + } + }, + "teaser-12" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:title" : "Teaser", + "actionsEnabled" : true, + "titleFromPage" : true, + "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", + "actions" : { + "jcr:primaryType" : "nt:unstructured", + "item0" : { + "jcr:primaryType" : "nt:unstructured", + "link": "http://www.adobe.com", + "text": "Adobe" + } + } + }, + "teaser-13" : { + "jcr:primaryType" : "nt:unstructured", + "fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", + "pretitle" : "Teaser's Pretitle", + "jcr:title" : "Teaser", + "jcr:description" : "Description", + "linkURL" : "https://www.adobe.com", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser", + "titleType" : "h4" + }, + "teaser-20" : { + "jcr:primaryType" : "nt:unstructured", + "linkURL" : "/content/teasers", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-21" : { + "jcr:primaryType" : "nt:unstructured", + "imageFromPageImage": "true", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-22" : { + "jcr:primaryType" : "nt:unstructured", + "imageFromPageImage": "true", + "linkURL": "/content/page1", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-22a" : { + "jcr:primaryType" : "nt:unstructured", + "imageFromPageImage": "true", + "linkURL": "/content/invalid_page", + "sling:resourceType": "core/wcm/components/teaser/v2/teaser" + }, + "teaser-23" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:title" : "Teaser", + "actionsEnabled" : true, + "titleFromPage" : true, + "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", + "linkURL": "/content/page1", + "actions" : { + "jcr:primaryType" : "nt:unstructured", + "item0" : { + "jcr:primaryType" : "nt:unstructured", + "link": "/content/page2", + "text": "Adobe" + }, + "item1" : { + "jcr:primaryType" : "nt:unstructured", + "link": "/content/non_existing1", + "text": "Adobe" + }, + "item2" : { + "jcr:primaryType" : "nt:unstructured", + "link": "/content/non_existing2", + "text": "Adobe" + } + }, + "imageFromPageImage": "true" + }, + "teaser-23a" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:title" : "Teaser", + "actionsEnabled" : true, + "titleFromPage" : true, + "sling:resourceType" : "core/wcm/components/teaser/v2/teaser", + "linkURL": "/content/page1", + "actions" : { + "jcr:primaryType" : "nt:unstructured", + "item0" : { + "jcr:primaryType" : "nt:unstructured", + "link": "/content/invalid_page2", + "text": "Adobe" + }, + "item1" : { + "jcr:primaryType" : "nt:unstructured", + "link": "/content/page2", + "text": "Adobe" + } + }, + "imageFromPageImage": "true" + } } + } + } + }, + "page1": { + "jcr:primaryType": "cq:Page", + "jcr:content" : { + "jcr:primaryType" : "cq:PageContent", + "jcr:title" : "Teasers Test", + "sling:resourceType": "core/wcm/components/page/v2/page", + "jcr:description" : "Page 1 description", + "cq:featuredimage" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:createdBy" : "admin", + "fileReference" : "/content/dam/core/images/asset1.png" + } + } + }, + "page2": { + "jcr:primaryType": "cq:Page", + "jcr:content" : { + "jcr:primaryType" : "cq:PageContent", + "jcr:title" : "Teasers Test", + "sling:resourceType": "core/wcm/components/page/v2/page", + "jcr:description" : "Page 2 description", + "cq:featuredimage" : { + "jcr:primaryType" : "nt:unstructured", + "jcr:createdBy" : "admin", + "fileReference" : "/content/dam/core/images/asset2.png" + } } + } }