From ce3c653bc9b9d49ff36f587dc5611cc33c378d11 Mon Sep 17 00:00:00 2001 From: Mitchell Bosecke Date: Sat, 8 Feb 2014 11:26:20 -0700 Subject: [PATCH] Fixed issue with how title filter handled leading whitespace. --- .../pebble/extension/core/TitleFilter.java | 2 +- .../mitchellbosecke/pebble/CoreFiltersTest.java | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mitchellbosecke/pebble/extension/core/TitleFilter.java b/src/main/java/com/mitchellbosecke/pebble/extension/core/TitleFilter.java index d8f2e2818..22f105e56 100644 --- a/src/main/java/com/mitchellbosecke/pebble/extension/core/TitleFilter.java +++ b/src/main/java/com/mitchellbosecke/pebble/extension/core/TitleFilter.java @@ -28,7 +28,7 @@ public Object apply(Object input, Map args) { boolean capitalizeNextCharacter = true; for (char c : value.toCharArray()) { - if (Character.isSpaceChar(c)) { + if (Character.isWhitespace(c)) { capitalizeNextCharacter = true; } else if (capitalizeNextCharacter) { c = Character.toTitleCase(c); diff --git a/src/test/java/com/mitchellbosecke/pebble/CoreFiltersTest.java b/src/test/java/com/mitchellbosecke/pebble/CoreFiltersTest.java index fc847925e..752c6f2d6 100644 --- a/src/test/java/com/mitchellbosecke/pebble/CoreFiltersTest.java +++ b/src/test/java/com/mitchellbosecke/pebble/CoreFiltersTest.java @@ -263,11 +263,11 @@ public void testCapitalizeWithLeadingWhitespace() throws PebbleException, IOExce Loader loader = new StringLoader(); PebbleEngine pebble = new PebbleEngine(loader); - PebbleTemplate template = pebble.compile("{{ ' this should be capitalized.' | capitalize }}"); + PebbleTemplate template = pebble.compile("{{ ' \nthis should be capitalized.' | capitalize }}"); Writer writer = new StringWriter(); template.evaluate(writer); - assertEquals(" This should be capitalized.", writer.toString()); + assertEquals(" \nThis should be capitalized.", writer.toString()); } @Test @@ -305,6 +305,18 @@ public void testTitle() throws PebbleException, IOException { template.evaluate(writer); assertEquals(" Test Test Test TEST TEST", writer.toString()); } + + @Test + public void testTitleWithLeadingWhitespace() throws PebbleException, IOException { + Loader loader = new StringLoader(); + PebbleEngine pebble = new PebbleEngine(loader); + + PebbleTemplate template = pebble.compile("{{ ' \ntest' | title }}"); + + Writer writer = new StringWriter(); + template.evaluate(writer); + assertEquals(" \nTest", writer.toString()); + } @Test public void testTrim() throws PebbleException, IOException {