#19353: Fixing more tokenizer escape sequences

Work Item: 19353

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-05-06 17:59:14 -07:00
parent 37a16c3fe1
commit 369a1a97a7
2 changed files with 10 additions and 14 deletions

View File

@@ -61,25 +61,13 @@ namespace Orchard.Tokens.Implementation {
for (var i = 0; i < text.Length; i++) {
var c = text[i];
if (!inToken && hashMode) {
if (c == '#' && i + 1 < text.Length) {
c = text[i + 1];
if (c == '{') {
i++;
}
else {
continue;
}
}
}
if (c == '{') {
if (i + 1 < text.Length && text[i + 1] == '{') {
text = text.Substring(0, i) + text.Substring(i + 1);
continue;
}
}
else if (c == '}') {
else if (c == '}' && !(inToken)) {
if (i + 1 < text.Length && text[i + 1] == '}') {
text = text.Substring(0, i) + text.Substring(i + 1);
continue;
@@ -93,10 +81,16 @@ namespace Orchard.Tokens.Implementation {
tokens.Add(token);
}
}
else if (c == '{') {
else if (!hashMode && c == '{') {
inToken = true;
tokenStart = i;
}
else if (hashMode && c == '#'
&& i + 1 < text.Length && text[i + 1] == '{'
&& (i + 2 > text.Length || text[i + 2] != '{') ) {
inToken = true;
tokenStart = i+1;
}
}
}
return new Tuple<string, IEnumerable<string>>(text, tokens);

View File

@@ -59,6 +59,7 @@ namespace Orchard.Tokens.Tests {
[Test]
public void TestTokenEscapeSequences() {
Assert.That(_tokenizer.Replace("{{escaped}} {Site.Global1} }}{{ {{{{ }}}}", null), Is.EqualTo("{escaped} [global1] }{ {{ }}"));
Assert.That(_tokenizer.Replace("{{{Site.Global1}}}", null), Is.EqualTo("{[global1]}"));
Assert.That(_tokenizer.Replace("{Date.Now.{{yyyy}}}", null), Is.EqualTo(DateTime.UtcNow.ToString("{yyyy}")));
}
@@ -92,6 +93,7 @@ namespace Orchard.Tokens.Tests {
[Test]
public void SimplePatterShouldBeIgnoredWhenHashIsPresent() {
Assert.That(_tokenizer.Replace("#{Site.Global1}", null), Is.EqualTo("[global1]"));
Assert.That(_tokenizer.Replace("{#{Site.Global1}}", null), Is.EqualTo("{[global1]}"));
Assert.That(_tokenizer.Replace("{Site.Global1}#{Site.Global1}", null), Is.EqualTo("{Site.Global1}[global1]"));
}