diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java index d194bfd5..c7c137b1 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java @@ -145,7 +145,7 @@ protected CharSequence safeApply(final Object context, final Options options) { join { @Override public Object apply(final Object context, final Options options) { - if (options.isFalsy(context)) { + if (options.isFalsy(context) && !(context instanceof CharSequence)) { return ""; } return safeApply(context, options); diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java index 363c12e6..8ace17b4 100644 --- a/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java +++ b/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java @@ -180,6 +180,37 @@ public void joinValues() throws IOException { "{{{join \"6\" 7 n8 \"-\"}}}", $("n8", 8), $("join", StringHelpers.join), "6-7-8"); } + @Test + public void joinEmptyStringValues() throws IOException { + shouldCompileTo( + "{{{join \"\" \"7\" 8 \"-\" prefix='<' suffix='>'}}}", + $, + $("join", StringHelpers.join), + "<-7-8>"); + } + + @Test + public void joinEmptyStringInSubexpression() throws IOException { + shouldCompileTo( + "{{#*inline \"anchor\"}}{{anchorId}}{{/inline}}" + + "{{> anchor anchorId=(join anchorId jsonPathPiece.snakeCase \"\")}}", + $("anchorId", "", "jsonPathPiece", $("snakeCase", "user_name")), + $("join", StringHelpers.join), + "user_name"); + } + + @Test + public void joinEmptyCharSequence() throws IOException { + shouldCompileTo( + "{{join this \"tail\" \"\"}}", new StringBuilder(), $("join", StringHelpers.join), "tail"); + } + + @Test + public void joinEmptyStringInBlock() throws IOException { + shouldCompileTo( + "{{#join \"\" \"tail\" \"\"}}{{/join}}", $, $("join", StringHelpers.join), "tail"); + } + @Test public void joinWithPrefixAndSuffix() throws IOException { shouldCompileTo(