@@ -40,24 +40,18 @@ public static string SetQueryParam(this string url, string key, string val)
40
40
var qsPos = url . IndexOf ( '?' ) ;
41
41
if ( qsPos != - 1 )
42
42
{
43
- int existingKeyPos ;
44
- if ( qsPos + 1 == url . IndexOf ( key , qsPos , PclExport . Instance . InvariantComparison ) )
45
- {
46
- existingKeyPos = qsPos + 1 ;
47
- }
48
- else
49
- {
50
- existingKeyPos = url . IndexOf ( "&" + key , qsPos , PclExport . Instance . InvariantComparison ) ;
51
- if ( existingKeyPos != - 1 )
52
- existingKeyPos ++ ;
53
- }
43
+ var existingKeyPos = qsPos + 1 == url . IndexOf ( key , qsPos , PclExport . Instance . InvariantComparison )
44
+ ? qsPos
45
+ : url . IndexOf ( "&" + key , qsPos , PclExport . Instance . InvariantComparison ) ;
54
46
55
47
if ( existingKeyPos != - 1 )
56
48
{
57
- var endPos = url . IndexOf ( '&' , existingKeyPos ) ;
58
- if ( endPos == - 1 ) endPos = url . Length ;
49
+ var endPos = url . IndexOf ( '&' , existingKeyPos + 1 ) ;
50
+ if ( endPos == - 1 )
51
+ endPos = url . Length ;
59
52
60
53
var newUrl = url . Substring ( 0 , existingKeyPos + key . Length + 1 )
54
+ + "="
61
55
+ val . UrlEncode ( )
62
56
+ url . Substring ( endPos ) ;
63
57
return newUrl ;
@@ -85,13 +79,18 @@ public static string SetHashParam(this string url, string key, string val)
85
79
var hPos = url . IndexOf ( '#' ) ;
86
80
if ( hPos != - 1 )
87
81
{
88
- var existingKeyPos = url . IndexOf ( key , hPos , PclExport . Instance . InvariantComparison ) ;
82
+ var existingKeyPos = hPos + 1 == url . IndexOf ( key , hPos , PclExport . Instance . InvariantComparison )
83
+ ? hPos
84
+ : url . IndexOf ( "/" + key , hPos , PclExport . Instance . InvariantComparison ) ;
85
+
89
86
if ( existingKeyPos != - 1 )
90
87
{
91
- var endPos = url . IndexOf ( '/' , existingKeyPos ) ;
92
- if ( endPos == - 1 ) endPos = url . Length ;
88
+ var endPos = url . IndexOf ( '/' , existingKeyPos + 1 ) ;
89
+ if ( endPos == - 1 )
90
+ endPos = url . Length ;
93
91
94
92
var newUrl = url . Substring ( 0 , existingKeyPos + key . Length + 1 )
93
+ + "="
95
94
+ val . UrlEncode ( )
96
95
+ url . Substring ( endPos ) ;
97
96
return newUrl ;
0 commit comments