Allows variable names containing a blank in the template engine.

This commit is contained in:
hneemann 2018-03-13 00:00:30 +01:00
parent 409bb3cac9
commit 13f2e6aec3
2 changed files with 19 additions and 2 deletions

View File

@ -183,6 +183,12 @@ public class Tokenizer {
while ((c = readChar()) != '"')
builder.append((char) c);
break;
case '\'':
token = Token.IDENT;
builder.setLength(0);
while ((c = readChar()) != '\'')
builder.append((char) c);
break;
case '?':
if (isNextChar('>'))
token = Token.CODEEND;
@ -326,11 +332,12 @@ public class Tokenizer {
int c;
while ((c = in.read()) > 0) {
if (c == '<') {
c = in.read();
if (c == '?') {
int cc = in.read();
if (cc == '?') {
return sb.toString();
} else {
sb.append((char) c);
sb.append((char) cc);
}
} else {
if (c == '\n')

View File

@ -104,11 +104,21 @@ public class ParserTest extends TestCase {
return c;
}
public void testParseTemplateTextOnly() throws IOException, ParserException, EvalException {
assertEquals("Hello World!", exec("Hello World!").toString());
assertEquals("Hello < < World!", exec("Hello < < World!").toString());
}
public void testParseTemplateVariable() throws IOException, ParserException, EvalException {
Context c = exec("Hello <? =a ?> World!", new Context().setVar("a", "My"));
assertEquals("Hello My World!", c.toString());
}
public void testParseTemplateVariableEscape() throws IOException, ParserException, EvalException {
Context c = exec("Hello <? ='a a' ?> World!", new Context().setVar("a a", "My"));
assertEquals("Hello My World!", c.toString());
}
public void testParseTemplateCodeOnly() throws IOException, ParserException, EvalException {
Context c = exec("<? =a ?>", new Context().setVar("a", "My"));
assertEquals("My", c.toString());