-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding url encoding wrapper function to handle xaml textbox conversio…
…n of new line to only carriage return
- Loading branch information
Showing
5 changed files
with
49 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Org.BouncyCastle.Utilities.Encoders; | ||
|
||
namespace DevToys.Helpers | ||
{ | ||
internal static class UrlHelper | ||
{ | ||
/// <summary> | ||
/// Url encodes a string. | ||
/// This is a wrapper function for the built in System.Uri api to accommodate this issue: | ||
/// https://github.com/microsoft/microsoft-ui-xaml/issues/1826 | ||
/// </summary> | ||
/// <param name="data">Input to url encode</param> | ||
/// <returns>Url encoded result</returns> | ||
internal static string UrlEncode(string data) | ||
{ | ||
string newLineAdjusted = data.Replace("\r\n", "\n").Replace("\r", "\n"); | ||
string encoded = Uri.EscapeDataString(newLineAdjusted); | ||
|
||
return encoded; | ||
} | ||
} | ||
} |
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,18 @@ | ||
using DevToys.Helpers; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace DevToys.Tests.Helpers | ||
{ | ||
[TestClass] | ||
public class UrlHelperTests | ||
{ | ||
[DataTestMethod] | ||
[DataRow("123\r456", "123%0A456")] | ||
[DataRow("test\r", "test%0A")] | ||
[DataRow("hello\r\nworld", "hello%0Aworld")] | ||
public void EncodeNewLines(string input, string expectedResult) | ||
{ | ||
Assert.AreEqual(expectedResult, UrlHelper.UrlEncode(input)); | ||
} | ||
} | ||
} |