From 5ab02d7a20d006241e35a901432e61bfd9d3f2b4 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 20 Nov 2026 18:35:29 +0800 Subject: [PATCH 1/2] Allow join to append to an empty string --- .../java/com/github/jknack/handlebars/helper/StringHelpers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 1cfc79c6b7c5cf1ad624151adfb54aa3e9e9e767 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 20 Nov 2026 18:35:56 +0800 Subject: [PATCH 2/2] Cover empty strings in join templates --- .../handlebars/helper/StringHelpersTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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(