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)
134134 . Replace ( TypeSerializer . DoubleQuoteString , JsWriter . QuoteString ) ;
135135 }
136136
137- public static string UrlEncode ( this string text )
137+ public static string UrlEncode ( this string text , bool upperCase = false )
138138 {
139139 if ( String . IsNullOrEmpty ( text ) ) return text ;
140140
141141 var sb = new StringBuilder ( ) ;
142+ var fmt = upperCase ? "X2" : "x2" ;
142143
143144 foreach ( var charCode in Encoding . UTF8 . GetBytes ( text ) )
144145 {
@@ -158,7 +159,7 @@ public static string UrlEncode(this string text)
158159 }
159160 else
160161 {
161- sb . Append ( '%' + charCode . ToString ( "x2" ) ) ;
162+ sb . Append ( '%' + charCode . ToString ( fmt ) ) ;
162163 }
163164 }
164165
Original file line number Diff line number Diff line change @@ -127,6 +127,14 @@ public void Can_Url_Encode_String()
127127 Assert . That ( decoded , Is . EqualTo ( text ) ) ;
128128 }
129129
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+
130138 [ Test ]
131139 public void Can_ToCamelCase_String ( )
132140 {
You can’t perform that action at this time.
0 commit comments