@@ -34,32 +34,6 @@ public static string DecodeBase64(this string input)
3434 return Encoding . UTF8 . GetString ( Convert . FromBase64String ( input ) ) ;
3535 }
3636
37- /// <summary>
38- /// Encode a string for URL transfer
39- /// </summary>
40- public static string EncodeUrl ( this string input )
41- {
42- if ( string . IsNullOrEmpty ( input ) )
43- {
44- return input ;
45- }
46-
47- return HttpUtility . UrlEncode ( input ) ;
48- }
49-
50- /// <summary>
51- /// Decodes a Url Encodeded String
52- /// </summary>
53- public static string DecodeUrl ( this string input )
54- {
55- if ( string . IsNullOrEmpty ( input ) )
56- {
57- return input ;
58- }
59-
60- return HttpUtility . UrlDecode ( input ) ;
61- }
62-
6337 /// <summary>
6438 /// Encode a string in Base64 for URL transfer
6539 /// </summary>
@@ -70,12 +44,11 @@ public static string DecodeUrl(this string input)
7044 return null ;
7145 }
7246
73- if ( input . HasInvalidUrlCharacters ( ) )
74- {
75- return $ "xurl_{ input . EncodeBase64 ( ) . EncodeUrl ( ) } ";
76- }
77-
78- return input ;
47+ var url = input . EncodeBase64 ( ) ;
48+ url = url . Replace ( '+' , '-' )
49+ . Replace ( '/' , '_' )
50+ . Replace ( '=' , '.' ) ;
51+ return $ "base64_{ url } ";
7952 }
8053
8154 /// <summary>
@@ -88,21 +61,17 @@ public static string DecodeUrl(this string input)
8861 return null ;
8962 }
9063
91- if ( ! input . StartsWith ( "xurl_ " ) )
64+ if ( ! input . StartsWith ( "base64_ " ) )
9265 {
9366 return input ;
9467 }
9568
96- var substr = input . Substring ( 5 ) ;
97- return DecodeUrl ( substr ) . DecodeBase64 ( ) ;
98- }
99-
100- /// <summary>
101- /// Indicates if the string has invalid characters
102- /// </summary>
103- public static bool HasInvalidUrlCharacters ( this string input )
104- {
105- return input . EncodeUrl ( ) != input ;
69+ var url = input . Substring ( 7 )
70+ . Replace ( '-' , '+' )
71+ . Replace ( '_' , '/' )
72+ . Replace ( '.' , '=' ) ;
73+ url = url . DecodeBase64 ( ) ;
74+ return url ;
10675 }
10776
10877 public static int GetDeterministicHashCode ( this string str )
0 commit comments