-
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.
- Loading branch information
1 parent
913a85e
commit 685aa72
Showing
8 changed files
with
99 additions
and
0 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/EscapeHtml.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 EscapeHtmlFunction : StringOneArgFunction | ||
{ | ||
public EscapeHtmlFunction() | ||
: base("EscapeHtml", TexlStrings.AboutEscapeHtml, FunctionCategories.Text) | ||
{ | ||
} | ||
|
||
public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures() | ||
{ | ||
yield return new[] { TexlStrings.EscapeHtmlArg1 }; | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/tests/Microsoft.PowerFx.Core.Tests/ExpressionTestCases/EscapeHtml.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Escaping | ||
>> EscapeHtml("<p>A paragraph</p>") | ||
"<p>A paragraph</p>" | ||
|
||
// Multiple encodings | ||
>> EscapeHtml("<h1>Mac & cheese</h1>") | ||
"<h1>Mac & cheese</h1>" | ||
|
||
// Quotes | ||
>> EscapeHtml("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))) | ||
" ¡¢£¤¥¦§¨©ª«¬­®¯" | ||
|
||
// \u0090 to \u009f - not escaped | ||
>> With({str:Concat(Sequence(16, 144), UniChar(Value))}, str = EscapeHtml(str)) | ||
true | ||
|
||
// \u00A0 to \u00ff - escaped | ||
>> With({str:EscapeHtml(Concat(Sequence(96, 160), UniChar(Value))), expectedEscaped:Concat(Sequence(96, 160), $"&#{Value};")}, str = expectedEscaped) | ||
true | ||
|
||
// \u0100... not escaped | ||
>> EscapeHtml("<b>ĀāĂă</b>") | ||
"<b>ĀāĂă</b>" | ||
|
||
// Blanks | ||
>> EscapeHtml(Blank()) | ||
"" | ||
|
||
// Errors | ||
>> EscapeHtml(Char(-1)) | ||
Error({Kind:ErrorKind.InvalidArgument}) | ||
|
||
// Escaping surrogate pairs | ||
>> EscapeHtml("<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): 𐒰𐒱𐒲𐒳𐒴𐒵𐒶") | ||
"Osage alphabet (start): 𐒰𐒱𐒲𐒳𐒴𐒵𐒶" |
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 |
---|---|---|
|
@@ -50,6 +50,7 @@ | |
"EndsWith", | ||
"EOMonth", | ||
"Error", | ||
"EscapeHtml", | ||
"Exp", | ||
"Filter", | ||
"Find", | ||
|