diff --git a/Runtime/Scripting/DomProxies/EncodingHelpers.cs b/Runtime/Scripting/DomProxies/EncodingHelpers.cs index daff7d60..92da638b 100644 --- a/Runtime/Scripting/DomProxies/EncodingHelpers.cs +++ b/Runtime/Scripting/DomProxies/EncodingHelpers.cs @@ -1,44 +1,27 @@ using System; -using System.Reflection; -using UnityEngine.Networking; namespace ReactUnity { public static class EncodingHelpers { - private static Type WWWTranscoder; - private static MethodInfo URLEncode; - private static MethodInfo URLDecode; - private static MethodInfo DataEncode; - private static MethodInfo DataDecode; - - static EncodingHelpers() - { - WWWTranscoder = typeof(UnityWebRequest).Assembly?.GetType("UnityEngine.WWWTranscoder"); - } - public static string encodeURI(string input) { - URLEncode = URLEncode ?? WWWTranscoder?.GetMethod("URLEncode", new Type[] { typeof(string) }); - return URLEncode?.Invoke(null, new object[] { input }) as string ?? input; + return Uri.EscapeUriString(input); } public static string decodeURI(string input) { - URLDecode = URLDecode ?? WWWTranscoder?.GetMethod("URLDecode", new Type[] { typeof(string) }); - return URLDecode?.Invoke(null, new object[] { input }) as string ?? input; + return Uri.UnescapeDataString(input); } public static string encodeURIComponent(string input) { - DataEncode = DataEncode ?? WWWTranscoder?.GetMethod("DataEncode", new Type[] { typeof(string) }); - return DataEncode?.Invoke(null, new object[] { input }) as string ?? input; + return Uri.EscapeDataString(input); } public static string decodeURIComponent(string input) { - DataDecode = DataDecode ?? WWWTranscoder?.GetMethod("DataDecode", new Type[] { typeof(string) }); - return DataDecode?.Invoke(null, new object[] { input }) as string ?? input; + return Uri.UnescapeDataString(input); } } } diff --git a/Tests/Editor/Renderer/MiscTests.cs b/Tests/Editor/Renderer/MiscTests.cs index 7160b020..0466ada6 100644 --- a/Tests/Editor/Renderer/MiscTests.cs +++ b/Tests/Editor/Renderer/MiscTests.cs @@ -28,7 +28,7 @@ public IEnumerator EncodingHelpersWork() yield return null; Assert.AreEqual( - "bla%26bla%26bla", + "bla&bla&bla", Context.Script.EvaluateScript(@"encodeURI('bla&bla&bla')") ); @@ -40,13 +40,13 @@ public IEnumerator EncodingHelpersWork() Assert.AreEqual( - "%5c%25+%2b", + "%5C%25%20+", Context.Script.EvaluateScript(@"encodeURI('\\% +')") ); Assert.AreEqual( - "%5c%25%20%2b", + "%5C%25%20%2B", Context.Script.EvaluateScript(@"encodeURIComponent('\\% +')") );