Skip to content

Commit 446d8e6

Browse files
committed
Fixed apply method to check for escape characters
1 parent d9f4ccc commit 446d8e6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gui/base/src/main/java/it/angrybear/yagl/Metadatable.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.lang.reflect.Field;
99
import java.util.*;
1010
import java.util.function.Function;
11+
import java.util.regex.Matcher;
12+
import java.util.regex.Pattern;
1113
import java.util.stream.Collectors;
1214

1315
/**
@@ -143,8 +145,11 @@ else if (!ReflectionUtils.isPrimitiveOrWrapper(object.getClass())) {
143145
default String apply(@NotNull String string) {
144146
for (final String v : this) {
145147
final String s = getVariable(v);
146-
if (s != null)
147-
string = string.replace(VARIABLE_FORMAT.apply(v), s);
148+
if (s == null) continue;
149+
final Matcher matcher = Pattern.compile("([^\\\\]|^)" + VARIABLE_FORMAT.apply(v)).matcher(string);
150+
while (matcher.find())
151+
string = string.substring(0, matcher.start()) + matcher.group(1) + s +
152+
string.substring(matcher.end());
148153
}
149154
return string;
150155
}

0 commit comments

Comments
 (0)