This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
tests/ServiceStack.Text.Tests Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -134,11 +134,12 @@ public static string DecodeJsv(this string value)
134
134
. Replace ( TypeSerializer . DoubleQuoteString , JsWriter . QuoteString ) ;
135
135
}
136
136
137
- public static string UrlEncode ( this string text )
137
+ public static string UrlEncode ( this string text , bool upperCase = false )
138
138
{
139
139
if ( String . IsNullOrEmpty ( text ) ) return text ;
140
140
141
141
var sb = new StringBuilder ( ) ;
142
+ var fmt = upperCase ? "X2" : "x2" ;
142
143
143
144
foreach ( var charCode in Encoding . UTF8 . GetBytes ( text ) )
144
145
{
@@ -158,7 +159,7 @@ public static string UrlEncode(this string text)
158
159
}
159
160
else
160
161
{
161
- sb . Append ( '%' + charCode . ToString ( "x2" ) ) ;
162
+ sb . Append ( '%' + charCode . ToString ( fmt ) ) ;
162
163
}
163
164
}
164
165
Original file line number Diff line number Diff line change @@ -127,6 +127,14 @@ public void Can_Url_Encode_String()
127
127
Assert . That ( decoded , Is . EqualTo ( text ) ) ;
128
128
}
129
129
130
+ [ Test ]
131
+ public void Can_UrlEncode_in_upper_case ( )
132
+ {
133
+ var chars = "/=" ;
134
+ Assert . That ( chars . UrlEncode ( ) , Is . EqualTo ( "%2f%3d" ) ) ;
135
+ Assert . That ( chars . UrlEncode ( upperCase : true ) , Is . EqualTo ( "%2F%3D" ) ) ;
136
+ }
137
+
130
138
[ Test ]
131
139
public void Can_ToCamelCase_String ( )
132
140
{
You can’t perform that action at this time.
0 commit comments