Skip to content

Commit 91b98ea

Browse files
committed
fix a bug in the inverter
1 parent d4effc0 commit 91b98ea

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

compiler/src/main/java/com/github/mustachejava/codes/ValueCode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ protected void execute(Writer writer, String value) throws IOException {
136136
@Override
137137
public Node invert(Node node, String text, AtomicInteger position) {
138138
if (compiledAppended == null) {
139-
compiledAppended = Pattern.compile(appended);
139+
if (appended == null) {
140+
compiledAppended = Pattern.compile("$");
141+
} else {
142+
compiledAppended = Pattern.compile(appended);
143+
}
140144
}
141145
int start = position.get();
142146
Matcher matcher = compiledAppended.matcher(text);

compiler/src/test/java/com/github/mustachejava/inverter/InverterTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.mustachejava.DefaultMustacheFactory;
44
import com.github.mustachejava.Mustache;
5+
import com.github.mustachejava.MustacheFactory;
56
import com.github.mustachejava.util.Node;
67
import org.junit.Test;
78

@@ -10,11 +11,13 @@
1011
import java.io.StringWriter;
1112
import java.nio.file.Files;
1213
import java.nio.file.Path;
14+
import java.util.UUID;
1315

1416
import static com.github.mustachejava.util.NodeValue.list;
1517
import static com.github.mustachejava.util.NodeValue.value;
1618
import static java.util.Arrays.asList;
1719
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotNull;
1821

1922
public class InverterTest extends InvertUtils {
2023

@@ -54,4 +57,13 @@ public void testIterable() throws IOException {
5457
test.execute(sw, invert).close();
5558
System.out.println(sw);
5659
}
60+
61+
@Test
62+
public void testCollectPoints() throws Exception {
63+
MustacheFactory dmf = new DefaultMustacheFactory();
64+
Mustache compile = dmf.compile(new StringReader("{{#page}}This is a {{test}}{{/page}}"),
65+
UUID.randomUUID().toString());
66+
Node node = compile.invert("This is a good day");
67+
assertNotNull(node);
68+
}
5769
}

javascript/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>com.github.spullara.mustache.java</groupId>
7+
<artifactId>mustache.java</artifactId>
8+
<version>0.8.15-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>javascript</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>com.github.spullara.mustache.java</groupId>
17+
<artifactId>compiler</artifactId>
18+
<version>0.8.15-SNAPSHOT</version>
19+
</dependency>
20+
</dependencies>
21+
</project>

0 commit comments

Comments
 (0)