public void EncodeStringWithSpaceSetting(string?strEncoded, string?strDecoded) { var settings = new UrlEncodingSettings(); settings.EncodedSpaceChar = '+'; Assert.AreEqual(strEncoded, UrlEncoding.Encode(strDecoded, settings)); }
public void ChangeBytePrefixCharEncode() { var settings = new UrlEncodingSettings(); settings.EncodedBytePrefixChar = '+'; Assert.AreEqual("Hi+2c+20there", UrlEncoding.Encode("Hi, there", settings)); Assert.AreEqual("Hi+2c+20there+20Ed+2e", UrlEncoding.Encode("Hi, there Ed.", settings)); }
public void UppercaseHexDigits() { var settings = new UrlEncodingSettings(); Assert.AreEqual("Hi, there", UrlEncoding.Decode("Hi%2c%20there", settings)); settings.UppercaseHexDigits = true; Assert.AreEqual("Hi, there", UrlEncoding.Decode("Hi%2C%20there", settings)); }
public void ChangeEncoding() { var settings = new UrlEncodingSettings(); settings.TextEncoding = Encoding.UTF32; Assert.AreEqual("Hi%2c%00%00%00%20%00%00%00there", UrlEncoding.Encode("Hi, there", settings)); Assert.AreEqual("Hi%2c%00%00%00%20%00%00%00there%20%00%00%00Ed%2e%00%00%00", UrlEncoding.Encode("Hi, there Ed.", settings)); }
public void OnlyEncodeSpaces() { var settings = new UrlEncodingSettings(); settings.ShouldEncodeChar = ch => ch == ' '; Assert.AreEqual("Hi,%20there", UrlEncoding.Encode("Hi, there", settings)); Assert.AreEqual("Hi,%20there%20Ed.", UrlEncoding.Encode("Hi, there Ed.", settings)); }
public void ChangeBytePrefixCharToBackslashEncode() { var settings = new UrlEncodingSettings(); settings.EncodedBytePrefixChar = '\\'; Assert.AreEqual("Hi\\2c\\20there", UrlEncoding.Encode("Hi, there", settings)); Assert.AreEqual("Hi\\2c\\20there\\20Ed\\2e", UrlEncoding.Encode("Hi, there Ed.", settings)); }
public void OnlyEncodeSpaces() { UrlEncodingSettings settings = new UrlEncodingSettings(); settings.ShouldEncodeChar = delegate(char ch) { return(ch == ' '); }; Assert.AreEqual("Hi,%20there", UrlEncoding.Encode("Hi, there", settings)); Assert.AreEqual("Hi,%20there%20Ed.", UrlEncoding.Encode("Hi, there Ed.", settings)); }
public void EncodeStringWithSpaceCustomShouldEncode(string?strEncoded, string?strDecoded) { var settings = new UrlEncodingSettings { EncodedSpaceChar = '+', ShouldEncodeChar = ch => ch == 'e', }; Assert.AreEqual(strEncoded, UrlEncoding.Encode(strDecoded, settings)); Assert.AreEqual(strDecoded, UrlEncoding.Decode(strEncoded, settings)); }
public void SettingsFromSettings() { var settings = new UrlEncodingSettings(); settings.TextEncoding = Encoding.UTF32; var settingsNew = settings.Clone(); settingsNew.EncodedBytePrefixChar = '+'; Assert.AreEqual("Hi+2c+00+00+00+20+00+00+00there", UrlEncoding.Encode("Hi, there", settingsNew)); Assert.AreEqual("Hi+2c+00+00+00+20+00+00+00there+20+00+00+00Ed+2e+00+00+00", UrlEncoding.Encode("Hi, there Ed.", settingsNew)); }
public void SettingsClone() { var settings = new UrlEncodingSettings { EncodedBytePrefixChar = '!', EncodedSpaceChar = '$', PreventDoubleEncoding = true, UppercaseHexDigits = true, ShouldEncodeChar = ch => ch == '@', TextEncoding = Encoding.UTF32, }; var settingsClone = settings.Clone(); Assert.AreEqual(settings.EncodedBytePrefixChar, settingsClone.EncodedBytePrefixChar); Assert.AreEqual(settings.EncodedSpaceChar, settingsClone.EncodedSpaceChar); Assert.AreEqual(settings.PreventDoubleEncoding, settingsClone.PreventDoubleEncoding); Assert.AreEqual(settings.UppercaseHexDigits, settingsClone.UppercaseHexDigits); Assert.AreEqual(UrlEncoding.Encode("!@#$ 駉", settings), UrlEncoding.Encode("!@#$ 駉", settingsClone)); }