mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#19353: Fixing more tokenizer escape sequences
Work Item: 19353 --HG-- branch : 1.x
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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]"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user