Skip to content

Commit

Permalink
Fixed issue with how title filter handled leading whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbosecke committed Feb 8, 2014
1 parent 796bca5 commit ce3c653
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Object apply(Object input, Map<String, Object> 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);
Expand Down
16 changes: 14 additions & 2 deletions src/test/java/com/mitchellbosecke/pebble/CoreFiltersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ce3c653

Please sign in to comment.