-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into carlosff/json/unwrappedtables
- Loading branch information
Showing
8 changed files
with
106 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/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 }; | ||
} | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
src/tests/Microsoft.PowerFx.Core.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Escaping | ||
>> EncodeHTML("<p>A paragraph</p>") | ||
"<p>A paragraph</p>" | ||
|
||
// Multiple encodings | ||
>> EncodeHTML("<h1>Mac & cheese</h1>") | ||
"<h1>Mac & cheese</h1>" | ||
|
||
// Quotes | ||
>> EncodeHTML("A value with ""double"" and 'single' quotes") | ||
"A value with "double" and 'single' quotes" | ||
|
||
// \u00A0 to \u00af - escaped | ||
>> EncodeHTML(Concat(Sequence(16, 160), UniChar(Value))) | ||
" ¡¢£¤¥¦§¨©ª«¬­®¯" | ||
|
||
// \u0090 to \u009f - not escaped | ||
>> With({str:Concat(Sequence(16, 144), UniChar(Value))}, str = EncodeHTML(str)) | ||
true | ||
|
||
// \u00A0 to \u00ff - escaped | ||
>> With({str:EncodeHTML(Concat(Sequence(96, 160), UniChar(Value))), expectedEscaped:Concat(Sequence(96, 160), $"&#{Value};")}, str = expectedEscaped) | ||
true | ||
|
||
// \u0100... not escaped | ||
>> EncodeHTML("<b>ĀāĂă</b>") | ||
"<b>ĀāĂă</b>" | ||
|
||
// Blanks | ||
>> EncodeHTML(Blank()) | ||
"" | ||
|
||
>> EncodeHTML("") | ||
"" | ||
|
||
// Errors | ||
>> EncodeHTML(Char(-1)) | ||
Error({Kind:ErrorKind.InvalidArgument}) | ||
|
||
// Escaping surrogate pairs | ||
>> 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>" | ||
|
||
>> EncodeHTML("Osage alphabet (start): 𐒰𐒱𐒲𐒳𐒴𐒵𐒶") | ||
"Osage alphabet (start): 𐒰𐒱𐒲𐒳𐒴𐒵𐒶" | ||
|
||
// Unpaired surrogate characters become the replacement character U+FFFD | ||
>> EncodeHTML($"Unpaired: {Mid(UniChar(Hex2Dec("1f600")),1,1)} {Mid(UniChar(Hex2Dec("1f600")),2,1)}") = $"Unpaired: {UniChar(65533)} {UniChar(65533)}" | ||
true |
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 |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
"Distinct", | ||
"DropColumns", | ||
"EDate", | ||
"EncodeHTML", | ||
"EncodeUrl", | ||
"EndsWith", | ||
"EOMonth", | ||
|