Added Url encode / Url decode options
This commit is contained in:
parent
1ea4e00904
commit
bed6302ea8
|
@ -1461,10 +1461,35 @@ Odd
|
||||||
Assert.AreEqual(expected, actual, "Value field didn't work");
|
Assert.AreEqual(expected, actual, "Value field didn't work");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region UrlDecodeEncode
|
||||||
|
[TestMethod]
|
||||||
|
public void TestCompile_UrlEncode() {
|
||||||
|
FormatCompiler compiler = new FormatCompiler();
|
||||||
|
const string format = @"{{#urlencode}}https://google.com{{/urlencode}}";
|
||||||
|
Generator generator = compiler.Compile(format);
|
||||||
|
|
||||||
|
string actual = generator.Render(new {});
|
||||||
|
string expected = "https%3a%2f%2fgoogle.com";
|
||||||
|
Assert.AreEqual(expected, actual, "Value field didn't work");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestCompile_UrlDecode() {
|
||||||
|
FormatCompiler compiler = new FormatCompiler();
|
||||||
|
const string format = @"{{#urldecode}}https%3a%2f%2fgoogle.com{{/urldecode}}";
|
||||||
|
Generator generator = compiler.Compile(format);
|
||||||
|
|
||||||
|
string actual = generator.Render(new { });
|
||||||
|
string expected = "https://google.com";
|
||||||
|
Assert.AreEqual(expected, actual, "Value field didn't work");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,10 @@ namespace Mustache
|
||||||
_tagLookup.Add(gteTagDefinition.Name, gteTagDefinition);
|
_tagLookup.Add(gteTagDefinition.Name, gteTagDefinition);
|
||||||
LteTagDefinition lteTagDefinition = new LteTagDefinition();
|
LteTagDefinition lteTagDefinition = new LteTagDefinition();
|
||||||
_tagLookup.Add(lteTagDefinition.Name, lteTagDefinition);
|
_tagLookup.Add(lteTagDefinition.Name, lteTagDefinition);
|
||||||
|
UrlEncodeTagDefinition urlEncodeTagDefinition = new UrlEncodeTagDefinition();
|
||||||
|
_tagLookup.Add(urlEncodeTagDefinition.Name, urlEncodeTagDefinition);
|
||||||
|
UrlDecodeTagDefinition urlDecodeTagDefinition = new UrlDecodeTagDefinition();
|
||||||
|
_tagLookup.Add(urlDecodeTagDefinition.Name,urlDecodeTagDefinition);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
namespace Mustache {
|
||||||
|
class UrlDecodeTagDefinition: ContentTagDefinition {
|
||||||
|
public UrlDecodeTagDefinition()
|
||||||
|
: base("urldecode") {
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<NestedContext> GetChildContext(TextWriter writer, Scope keyScope, Dictionary<string, object> arguments, Scope contextScope) {
|
||||||
|
NestedContext context = new NestedContext() {
|
||||||
|
KeyScope = keyScope,
|
||||||
|
Writer = new StringWriter(),
|
||||||
|
WriterNeedsConsidated = true,
|
||||||
|
};
|
||||||
|
yield return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<TagParameter> GetChildContextParameters() {
|
||||||
|
return new TagParameter[] { new TagParameter("collection") };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ConsolidateWriter(TextWriter writer, Dictionary<string, object> arguments) {
|
||||||
|
return HttpUtility.UrlDecode(writer.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
namespace Mustache {
|
||||||
|
|
||||||
|
public class UrlEncodeTagDefinition : ContentTagDefinition {
|
||||||
|
public UrlEncodeTagDefinition()
|
||||||
|
: base("urlencode") {
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<NestedContext> GetChildContext(TextWriter writer,Scope keyScope,Dictionary<string, object> arguments,Scope contextScope) {
|
||||||
|
NestedContext context = new NestedContext() {
|
||||||
|
KeyScope = keyScope,
|
||||||
|
Writer = new StringWriter(),
|
||||||
|
WriterNeedsConsidated = true,
|
||||||
|
};
|
||||||
|
yield return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<TagParameter> GetChildContextParameters() {
|
||||||
|
return new TagParameter[] { new TagParameter("collection") };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ConsolidateWriter(TextWriter writer, Dictionary<string, object> arguments) {
|
||||||
|
return HttpUtility.UrlEncode(writer.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,6 +32,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Web" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="ArgumentCollection.cs" />
|
<Compile Include="ArgumentCollection.cs" />
|
||||||
|
@ -45,6 +46,8 @@
|
||||||
<Compile Include="LtTagDefinition.cs" />
|
<Compile Include="LtTagDefinition.cs" />
|
||||||
<Compile Include="EqTagDefinition.cs" />
|
<Compile Include="EqTagDefinition.cs" />
|
||||||
<Compile Include="GtTagDefinition.cs" />
|
<Compile Include="GtTagDefinition.cs" />
|
||||||
|
<Compile Include="UrlDecodeTagDefinition.cs" />
|
||||||
|
<Compile Include="UrlEncodeTagDefinition.cs" />
|
||||||
<Compile Include="VariableFoundEventArgs.cs" />
|
<Compile Include="VariableFoundEventArgs.cs" />
|
||||||
<Compile Include="SetTagDefinition.cs" />
|
<Compile Include="SetTagDefinition.cs" />
|
||||||
<Compile Include="NewlineTagDefinition.cs" />
|
<Compile Include="NewlineTagDefinition.cs" />
|
||||||
|
|
Loading…
Reference in New Issue