From d5470c303a374f9515097eeb58f2aabcc511576f Mon Sep 17 00:00:00 2001 From: Jose Galarza Date: Tue, 1 Aug 2017 16:39:08 +0300 Subject: [PATCH 1/2] Fixing filters with uppercase letters --- .../hubspot/jinjava/lib/SimpleLibrary.java | 4 +- .../CamelCaseRegisteringFilterTest.java | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/hubspot/jinjava/lib/filter/CamelCaseRegisteringFilterTest.java diff --git a/src/main/java/com/hubspot/jinjava/lib/SimpleLibrary.java b/src/main/java/com/hubspot/jinjava/lib/SimpleLibrary.java index 97598beb6..c40e406b5 100644 --- a/src/main/java/com/hubspot/jinjava/lib/SimpleLibrary.java +++ b/src/main/java/com/hubspot/jinjava/lib/SimpleLibrary.java @@ -57,7 +57,7 @@ public T fetch(String item) { throw new DisabledException(item); } - return lib.get(StringUtils.lowerCase(item)); + return lib.get(item); } @SafeVarargs @@ -82,7 +82,7 @@ public void register(T obj) { } public void register(String name, T obj) { - if (!disabled.contains(obj.getName().toLowerCase())) { + if (!disabled.contains(obj.getName())) { lib.put(name, obj); ENGINE_LOG.debug(getClass().getSimpleName() + ": Registered " + obj.getName()); } diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/CamelCaseRegisteringFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/CamelCaseRegisteringFilterTest.java new file mode 100644 index 000000000..2df0b0fee --- /dev/null +++ b/src/test/java/com/hubspot/jinjava/lib/filter/CamelCaseRegisteringFilterTest.java @@ -0,0 +1,37 @@ +package com.hubspot.jinjava.lib.filter; + +import com.hubspot.jinjava.Jinjava; +import com.hubspot.jinjava.interpret.JinjavaInterpreter; +import org.junit.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CamelCaseRegisteringFilterTest { + + Jinjava jinjava; + + @Test + public void testCamelCaseIsRegistered() { + jinjava = new Jinjava(); + jinjava.getGlobalContext().registerFilter(new ReturnHelloFilter()); + + assertThat(jinjava.render("{{ 'test'|returnHello }}", new HashMap<>())).isEqualTo("Hello"); + } + + private static class ReturnHelloFilter implements AdvancedFilter { + @Override + public String getName() { + return "returnHello"; + } + + @Override + public Object filter(Object var, JinjavaInterpreter interpreter, Object[] args, Map kwargs) { + return "Hello"; + } + } + +} From 1e45682bb333c51a551790669e32ab66d0fae5b3 Mon Sep 17 00:00:00 2001 From: Jeff Boulter Date: Tue, 1 Aug 2017 09:48:53 -0400 Subject: [PATCH 2/2] update test name --- .../jinjava/lib/filter/CamelCaseRegisteringFilterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/hubspot/jinjava/lib/filter/CamelCaseRegisteringFilterTest.java b/src/test/java/com/hubspot/jinjava/lib/filter/CamelCaseRegisteringFilterTest.java index 2df0b0fee..4232c47a8 100644 --- a/src/test/java/com/hubspot/jinjava/lib/filter/CamelCaseRegisteringFilterTest.java +++ b/src/test/java/com/hubspot/jinjava/lib/filter/CamelCaseRegisteringFilterTest.java @@ -15,7 +15,7 @@ public class CamelCaseRegisteringFilterTest { Jinjava jinjava; @Test - public void testCamelCaseIsRegistered() { + public void itAllowsCamelCasedFilterNames() { jinjava = new Jinjava(); jinjava.getGlobalContext().registerFilter(new ReturnHelloFilter());