diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index c0ae915d..0bd15685 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -317,7 +317,7 @@ For rendering HTML documents, `ContentType.Html` is highly recommended for [secu ### Smart Attributes -Expressions in HTML attributes are evaluated, so that optimal output is generated. This means attributes with a single output that evaluates to an empty string, null, or false, are not rendered. For instance: +Expressions in HTML attributes are evaluated, so that optimal output is generated. This means attributes with a single output that evaluates to null, or false, are not rendered. For instance: ```html Info diff --git a/jte-kotlin/src/test/java/gg/jte/kotlin/TemplateEngine_HtmlOutputEscapingTest.java b/jte-kotlin/src/test/java/gg/jte/kotlin/TemplateEngine_HtmlOutputEscapingTest.java index 3493593d..d215b327 100644 --- a/jte-kotlin/src/test/java/gg/jte/kotlin/TemplateEngine_HtmlOutputEscapingTest.java +++ b/jte-kotlin/src/test/java/gg/jte/kotlin/TemplateEngine_HtmlOutputEscapingTest.java @@ -470,7 +470,7 @@ void attributes_String_empty() { templateEngine.render("template.kte", "", output); - assertThat(output.toString()).isEqualTo(""); + assertThat(output.toString()).isEqualTo(""); } @Test diff --git a/jte-runtime/src/main/java/gg/jte/runtime/TemplateUtils.java b/jte-runtime/src/main/java/gg/jte/runtime/TemplateUtils.java index 680d54cc..a755d97d 100644 --- a/jte-runtime/src/main/java/gg/jte/runtime/TemplateUtils.java +++ b/jte-runtime/src/main/java/gg/jte/runtime/TemplateUtils.java @@ -53,7 +53,7 @@ public static boolean isAttributeRendered(double value) { } public static boolean isAttributeRendered(String value) { - return value != null && !value.isEmpty(); + return value != null; } public static boolean isAttributeRendered(Content value) { diff --git a/jte/src/test/java/gg/jte/TemplateEngine_HtmlOutputEscapingTest.java b/jte/src/test/java/gg/jte/TemplateEngine_HtmlOutputEscapingTest.java index 46419d1b..26653ea9 100644 --- a/jte/src/test/java/gg/jte/TemplateEngine_HtmlOutputEscapingTest.java +++ b/jte/src/test/java/gg/jte/TemplateEngine_HtmlOutputEscapingTest.java @@ -477,7 +477,20 @@ void attributes_String_empty() { templateEngine.render("template.jte", "", output); - assertThat(output.toString()).isEqualTo(""); + assertThat(output.toString()).isEqualTo(""); + } + + /** + * This is essentially the same test as gg.jte.TemplateEngine_HtmlOutputEscapingTest#attributes_String_empty() + * But it especially shows that there is a semantic difference between an empty String and null. + */ + @Test + void attributes_String_empty_option() { + codeResolver.givenCode("template.jte", "@param String value\n"); + + templateEngine.render("template.jte", "", output); + + assertThat(output.toString()).isEqualTo(""); } @Test