Skip to content

Commit

Permalink
Teaser: ensure description inherited from page properties is HTML-esc…
Browse files Browse the repository at this point in the history
…aped, because the teaser component expected the description to be valid HTML (from RTE), but the page properties dialog only provides a plain text field (#1883)
  • Loading branch information
stefanseifert authored and bpauli committed Nov 15, 2021
1 parent 08db14e commit 86eea6a
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &lt;page properties&gt;", teaser.getDescription());
}

@Test
Expand Down Expand Up @@ -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 &lt;page properties&gt;", teaser.getDescription());
Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser11"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &lt;page properties&gt;", teaser.getDescription());
Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser11"));
}

Expand Down
4 changes: 2 additions & 2 deletions bundles/core/src/test/resources/teaser/exporter-teaser11.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Teasers Test",
"description": "Teasers description",
"description": "Teasers description from &lt;page properties&gt;",
"linkURL": "/core/content/teasers.html",
"actionsEnabled": true,
"imageLinkHidden": false,
Expand Down Expand Up @@ -38,7 +38,7 @@
"dataLayer": {
"teaser-84f85e5d32": {
"xdm:linkURL": "/core/content/teasers.html",
"dc:description": "Teasers description",
"dc:description": "Teasers description from &lt;page properties&gt;",
"@type": "core/wcm/components/teaser/v1/teaser",
"dc:title": "Teasers Test"
}
Expand Down
2 changes: 1 addition & 1 deletion bundles/core/src/test/resources/teaser/test-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <page properties>",
"root" : {
"jcr:primaryType" : "nt:unstructured",
"sling:resourceType": "wcm/foundation/components/responsivegrid",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Teasers Test",
"description": "Teasers description",
"description": "Teasers description from &lt;page properties&gt;",
"link": {
"valid": true,
"url": "/core/content/teasers.html"
Expand Down Expand Up @@ -47,7 +47,7 @@
"dataLayer": {
"teaser-84f85e5d32": {
"xdm:linkURL": "/core/content/teasers.html",
"dc:description": "Teasers description",
"dc:description": "Teasers description from &lt;page properties&gt;",
"@type": "core/wcm/components/teaser/v2/teaser",
"dc:title": "Teasers Test"
}
Expand Down
Loading

0 comments on commit 86eea6a

Please sign in to comment.