-
Notifications
You must be signed in to change notification settings - Fork 43
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 #100 from xiaohai-huang/main
Fixed URI handling functions does not match JS spec
- Loading branch information
Showing
2 changed files
with
7 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
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