fixed bug in JWO.renderTemplate
All checks were successful
CI / build (push) Successful in 1m22s

This commit is contained in:
2025-01-17 10:32:32 +08:00
parent 89817c5624
commit 8436da536f
5 changed files with 17 additions and 16 deletions

View File

@@ -3,6 +3,6 @@ org.gradle.parallel=true
org.gradle.caching=true
gitea.maven.url = https://gitea.woggioni.net/api/packages/woggioni/maven
jwo.version = 2025.01.09
lys.version = 2025.01.08
jwo.version = 2025.01.17
lys.version = 2025.01.10
guice.version = 5.0.1

View File

@@ -346,13 +346,20 @@ public class JWO {
int cursor = 0;
while(cursor < template.length()) {
int nextPlaceHolder = indexOfWithEscape(template, '$', '$', cursor, template.length());
int nextPlaceHolder = template.indexOf('$', cursor);
if (nextPlaceHolder < 0) {
nextPlaceHolder = template.length();
}
while (cursor < nextPlaceHolder) {
char ch = template.charAt(cursor++);
sb.append(ch);
int nextPlaceHolderWithEscape = indexOfWithEscape(template, '$', '$', cursor, template.length());
if (nextPlaceHolderWithEscape < 0) {
nextPlaceHolderWithEscape = template.length();
}
while (cursor < nextPlaceHolderWithEscape) {
char ch = template.charAt(cursor);
if (nextPlaceHolder == nextPlaceHolderWithEscape || cursor != nextPlaceHolder) {
sb.append(ch);
}
++cursor;
}
if (cursor + 1 < template.length() && template.charAt(cursor + 1) == '{') {
String key;

View File

@@ -9,15 +9,6 @@ import java.net.URLStreamHandler;
import java.util.Optional;
public class Handler extends URLStreamHandler {
private final ClassLoader classLoader;
public Handler() {
this.classLoader = getClass().getClassLoader();
}
public Handler(ClassLoader classLoader) {
this.classLoader = classLoader;
}
@Override
protected URLConnection openConnection(URL u) throws IOException {

View File

@@ -158,6 +158,7 @@ public class JWOTest {
/home/user
/home/user
defaultValue
;=%x$!~L+LJr?50l.^{veaS'zLHo=!}wT
""";
Map<String, Map<String, Object>> contextMap = new MapBuilder<String, Map<String, Object>>()
.entry("env",
@@ -168,7 +169,8 @@ public class JWOTest {
.entry("sys",
new MapBuilder<String, String>()
.entry("user.home", "/home/user")
.build(TreeMap::new, Collections::unmodifiableMap)).build(TreeMap::new, Collections::unmodifiableMap);
.build(TreeMap::new, Collections::unmodifiableMap)
).build(TreeMap::new, Collections::unmodifiableMap);
try (Reader reader = new InputStreamReader(
JWOTest.class.getResourceAsStream("/render_template_test.txt"))) {
String rendered = JWO.renderTemplate(reader, valuesMap, contextMap);

View File

@@ -2,3 +2,4 @@ This is a ${adjective} test made by ${author} on ${date}. It's really ${adjectiv
${sys:user.home}
${env:HOME}
${env:SOME_STRANGE_VAR:defaultValue}
;=%x$$!~L+LJr?50l.^{veaS'zLHo=!}wT