-
Notifications
You must be signed in to change notification settings - Fork 231
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
The "\>" delimeter is not rendering correctly #198
Comments
The C# port (which is actually in the repository https://github.com/antlr/antlrcs) appears to behave the same way as the reference implementation. The only two characters escaped are the expression start delimiter ( stringtemplate4/src/org/stringtemplate/v4/compiler/STLexer.java Lines 428 to 429 in 9cc59e1
|
The behavior is in fact regression between 4.0.4 and 4.0.7 (I imagine due to tweaks here https://github.com/antlr/stringtemplate4/blob/master/CHANGES.txt#L27 ) Can this be fixed so it is consistent? I imagine that changing the escaping would break templates using 4.0.7+ (although people using 4.0.4 could finally upgrade), so perhaps it can be put behind some global configuration flag? ( Note that in 4.0.4 it was broken for ST, but not for STGFile nor STGString. 4.0.4:
4.0.7:
test code:
package sandbox;
import org.junit.Test;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroupFile;
import org.stringtemplate.v4.STGroupString;
import static org.junit.Assert.assertEquals;
public class STGTest {
@Test
public void test_escape_st() {
String s = "a <b> \\<c> \\<d\\>";
ST template = new ST(s);
String result = template.add("b", "BB").render();
assertEquals("a BB <c> <d>", result);
}
@Test
public void test_escape_stg_string() {
String s = "base(b) ::= <<a <b> \\<c> \\<d\\>>>";
STGroupString group = new STGroupString(s);
ST template = group.getInstanceOf("base");
String result = template.add("b", "BB").render();
assertEquals("a BB <c> <d>", result);
}
@Test
public void test_escape_stg_file() {
STGroupFile group = new STGroupFile("template.stg");
ST template = group.getInstanceOf("base");
String result = template.add("b", "BB").render();
assertEquals("a BB <c> <d>", result);
}
}
|
Thanks for the detailed analysis. We'll look at this for next release. |
Just to add to this, this issue is particularly devious in .stg files when the templates are wrapped in For example with the current behavior this happens: Given value == "Foo",
This leaves only the option of conditionally escaping |
Using
|
I'm using the c# port of stringtemplate 4.0.6.9004.
Per the cheatsheet, stringtemplate4 is supposed to recognize
\<
and\>
as escaped characters<
and>
. Escaping\<
works properly but\>
does not.This template worked correctly in stringtemplate3 but in upgrading to stringtemplate4, we see that the string
"\<\>"
rendering yields"<\>"
.The text was updated successfully, but these errors were encountered: