-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from sveinungf/dev/encoding
New XML encode implementation
- Loading branch information
Showing
24 changed files
with
356 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
M:System.IO.Compression.ZipArchive.CreateEntry(System.String);Pass CompressionLevel parameter | ||
M:System.Net.WebUtility.HtmlEncode(System.String);Use XmlUtility.XmlEncode | ||
P:System.Nullable`1.Value;GetValueOrDefault() or the coalesce operator do less work |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#if DEBUG | ||
using SpreadCheetah.Helpers; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace SpreadCheetah.Test.Tests; | ||
|
||
public static class XmlUtilityTests | ||
|
||
{ | ||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData("Just a regular string without any special characters", "Just a regular string without any special characters")] | ||
[InlineData("&", "&")] | ||
[InlineData("&<>'\"", "&<>'"")] | ||
[InlineData("&OnlyFirstCharacter", "&OnlyFirstCharacter")] | ||
[InlineData("&This<string>has'special\"characters in between", "&This<string>has'special"characters in between")] | ||
[InlineData("This<string>has'special\"characters in between&", "This<string>has'special"characters in between&")] | ||
[InlineData("\tHandling\r\nAllowed\nControl\tCharacters\n", "\tHandling\r\nAllowed\nControl\tCharacters\n")] | ||
[InlineData("\u0001Handling\u0002Invalid\u0003Control\u0004Characters\u0005", "HandlingInvalidControlCharacters")] | ||
[InlineData("\u0006", "")] | ||
[InlineData("\u0007\u0008", "")] | ||
public static void XmlUtility_TryXmlEncodeToUtf8_Success(string value, string expected) | ||
{ | ||
// Arrange | ||
var buffer = new byte[value.Length * 6]; | ||
|
||
// Act | ||
var result = XmlUtility.TryXmlEncodeToUtf8(value.AsSpan(), buffer, out var bytesWritten); | ||
|
||
// Assert | ||
Assert.True(result); | ||
|
||
var bytes = buffer.AsSpan(0, bytesWritten); | ||
var actual = Encoding.UTF8.GetString(bytes.ToArray()); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData("", "")] | ||
[InlineData("Just a regular string without any special characters", "Just a regular string without any special characters")] | ||
[InlineData("&", "&")] | ||
[InlineData("&<>'\"", "&<>'"")] | ||
[InlineData("&OnlyFirstCharacter", "&OnlyFirstCharacter")] | ||
[InlineData("&This<string>has'special\"characters in between", "&This<string>has'special"characters in between")] | ||
[InlineData("This<string>has'special\"characters in between&", "This<string>has'special"characters in between&")] | ||
[InlineData("\tHandling\r\nAllowed\nControl\tCharacters\n", "\tHandling\r\nAllowed\nControl\tCharacters\n")] | ||
[InlineData("\u0001Handling\u0002Invalid\u0003Control\u0004Characters\u0005", "HandlingInvalidControlCharacters")] | ||
[InlineData("\u0006", "")] | ||
[InlineData("\u0007\u0008", "")] | ||
public static void XmlUtility_XmlEncode_Success(string value, string expected) | ||
{ | ||
// Act | ||
var result = XmlUtility.XmlEncode(value); | ||
|
||
// Assert | ||
Assert.Equal(expected, result); | ||
} | ||
} | ||
#endif |
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
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 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
Oops, something went wrong.