Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown token in filter is treated as 0 #382 #648

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Object filter(Object object, JinjavaInterpreter interpreter, String... ar
}

if (args[0] == null) {
return base;
return null;
}

BigDecimal addend;
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/com/hubspot/jinjava/lib/filter/AddFilterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hubspot.jinjava.lib.filter;

import com.google.common.collect.ImmutableMap;
import com.hubspot.jinjava.BaseInterpretingTest;
import org.junit.Before;
import org.junit.Test;

import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

public class AddFilterTest extends BaseInterpretingTest {
private Map<String, Object> bindings;

@Before
public void setup() {
jinjava.getGlobalContext().registerClasses(AddFilter.class);

bindings = ImmutableMap.of(
"num1", 12,
"num2", 48
);
}

@Test
public void itAddsNumber() {
assertThat(jinjava.render("{{ 5|add(13) }}", bindings)).isEqualTo("18");
assertThat(jinjava.render("{{ num1|add(4) }}", bindings)).isEqualTo("16");
assertThat(jinjava.render("{{ 7|add(num2) }}", bindings)).isEqualTo("55");
assertThat(jinjava.render("{{ num1|add(num2) }}", bindings)).isEqualTo("60");
}
}