Skip to content

Commit

Permalink
Merge branch 'master' into release/1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalniski committed Apr 27, 2023
2 parents f73e7b3 + fc777d3 commit 3444f5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions html/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ dependencies {
api (project(":core"))
api "com.contentful.java:java-sdk:${project.contentful_version}"
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.apache.commons:commons-text:1.9'
implementation 'org.apache.commons:commons-text:1.10.0'
testImplementation 'com.google.truth:truth:0.42'
testImplementation 'junit:junit:4.13.1'
testImplementation 'junit:junit:4.13.2'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.contentful.rich.html.renderer.TagRenderer;
import com.contentful.rich.html.renderer.TagWithArgumentsRenderer;
import com.contentful.rich.html.renderer.TextRenderer;
import com.google.gson.internal.LinkedTreeMap;

import javax.annotation.Nonnull;
import java.util.Map;

import static com.contentful.rich.html.renderer.TagWithArgumentsRenderer.mapifyArguments;

Expand Down Expand Up @@ -61,11 +61,11 @@ void provide(@Nonnull Processor<HtmlContext, String> processor) {
(node) -> mapifyArguments("href", (String) ((CDARichHyperLink) node).getData()))
);
processor.addRenderer(
(context, node) -> node instanceof CDARichHyperLink && ((CDARichHyperLink) node).getData() instanceof LinkedTreeMap,
(context, node) -> node instanceof CDARichHyperLink && ((CDARichHyperLink) node).getData() instanceof Map,
new TagWithArgumentsRenderer(
processor,
"a",
(node) -> mapifyArguments("href", (String) ((LinkedTreeMap<?, ?>) ((CDARichHyperLink) node).getData()).get("uri")))
(node) -> mapifyArguments("href", (String) ((Map<?, ?>) ((CDARichHyperLink) node).getData()).get("uri")))
);
processor.addRenderer(
(context, node) -> node instanceof CDARichQuote,
Expand Down
20 changes: 20 additions & 0 deletions html/src/test/java/LinksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import static com.google.common.truth.Truth.assertThat;

Expand All @@ -28,6 +30,24 @@ public void renderLinkTest() {
"</a>\n");
}

@Test
public void renderLinkWithUriTest() {
final HtmlProcessor processor = new HtmlProcessor();
final HtmlContext context = new HtmlContext();

final Map<String, Object> linkProps = new HashMap<>();
linkProps.put("uri", "https://contentful.com");
final CDARichHyperLink link = new CDARichHyperLink(linkProps);
link.getContent().add(new CDARichText("Some link text<br/>", new ArrayList<>()));

final String result = processor.process(context, link);

assertThat(result).isEqualTo("" +
"<a href=\"https://contentful.com\">\n" +
" Some link text&lt;br/&gt;\n" +
"</a>\n");
}

@Test
public void createUnsanitzedStrings() {
final HtmlProcessor processor = new HtmlProcessor();
Expand Down

0 comments on commit 3444f5d

Please sign in to comment.