-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement EncodeHTML function and tests
- Loading branch information
1 parent
685aa72
commit ed43022
Showing
9 changed files
with
63 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/libraries/Microsoft.PowerFx.Core/Texl/Builtins/EncodeHTML.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.PowerFx.Core.Localization; | ||
using Microsoft.PowerFx.Core.Texl.Builtins; | ||
using Microsoft.PowerFx.Core.Types; | ||
|
||
namespace Microsoft.PowerFx.Core.Texl | ||
{ | ||
internal sealed class EncodeHTMLFunction : StringOneArgFunction | ||
{ | ||
public EncodeHTMLFunction() | ||
: base("EncodeHTML", TexlStrings.AboutEncodeHTML, FunctionCategories.Text) | ||
{ | ||
} | ||
|
||
public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures() | ||
{ | ||
yield return new[] { TexlStrings.EncodeHTMLArg1 }; | ||
} | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
src/libraries/Microsoft.PowerFx.Core/Texl/Builtins/EscapeHtml.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 18 additions & 11 deletions
29
....Tests/ExpressionTestCases/EscapeHtml.txt → ....Tests/ExpressionTestCases/EncodeHTML.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,49 @@ | ||
// Escaping | ||
>> EscapeHtml("<p>A paragraph</p>") | ||
>> EncodeHTML("<p>A paragraph</p>") | ||
"<p>A paragraph</p>" | ||
|
||
// Multiple encodings | ||
>> EscapeHtml("<h1>Mac & cheese</h1>") | ||
>> EncodeHTML("<h1>Mac & cheese</h1>") | ||
"<h1>Mac & cheese</h1>" | ||
|
||
// Quotes | ||
>> EscapeHtml("A value with ""double"" and 'single' quotes") | ||
>> EncodeHTML("A value with ""double"" and 'single' quotes") | ||
"A value with "double" and 'single' quotes" | ||
|
||
// \u00A0 to \u00af - escaped | ||
>> EscapeHtml(Concat(Sequence(16, 160), UniChar(Value))) | ||
>> EncodeHTML(Concat(Sequence(16, 160), UniChar(Value))) | ||
" ¡¢£¤¥¦§¨©ª«¬­®¯" | ||
|
||
// \u0090 to \u009f - not escaped | ||
>> With({str:Concat(Sequence(16, 144), UniChar(Value))}, str = EscapeHtml(str)) | ||
>> With({str:Concat(Sequence(16, 144), UniChar(Value))}, str = EncodeHTML(str)) | ||
true | ||
|
||
// \u00A0 to \u00ff - escaped | ||
>> With({str:EscapeHtml(Concat(Sequence(96, 160), UniChar(Value))), expectedEscaped:Concat(Sequence(96, 160), $"&#{Value};")}, str = expectedEscaped) | ||
>> With({str:EncodeHTML(Concat(Sequence(96, 160), UniChar(Value))), expectedEscaped:Concat(Sequence(96, 160), $"&#{Value};")}, str = expectedEscaped) | ||
true | ||
|
||
// \u0100... not escaped | ||
>> EscapeHtml("<b>ĀāĂă</b>") | ||
>> EncodeHTML("<b>ĀāĂă</b>") | ||
"<b>ĀāĂă</b>" | ||
|
||
// Blanks | ||
>> EscapeHtml(Blank()) | ||
>> EncodeHTML(Blank()) | ||
"" | ||
|
||
>> EncodeHTML("") | ||
"" | ||
|
||
// Errors | ||
>> EscapeHtml(Char(-1)) | ||
>> EncodeHTML(Char(-1)) | ||
Error({Kind:ErrorKind.InvalidArgument}) | ||
|
||
// Escaping surrogate pairs | ||
>> EscapeHtml("<ul><li>not a pair: ❤</li><li>a surrogate pair: 💩</li></ul>") | ||
>> EncodeHTML("<ul><li>not a pair: ❤</li><li>a surrogate pair: 💩</li></ul>") | ||
"<ul><li>not a pair: ❤</li><li>a surrogate pair: 💩</li></ul>" | ||
|
||
>> EscapeHtml("Osage alphabet (start): 𐒰𐒱𐒲𐒳𐒴𐒵𐒶") | ||
>> EncodeHTML("Osage alphabet (start): 𐒰𐒱𐒲𐒳𐒴𐒵𐒶") | ||
"Osage alphabet (start): 𐒰𐒱𐒲𐒳𐒴𐒵𐒶" | ||
|
||
// Unpaired surrogate characters become the replacement character U+FFFD | ||
>> EncodeHTML($"Unpaired: {UniChar(Hex2Dec("df32"))} {UniChar(Hex2Dec("d823"))}")) | ||
"Unpaired: � �" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters