@@ -40,24 +40,18 @@ public static string SetQueryParam(this string url, string key, string val)
4040            var  qsPos  =  url . IndexOf ( '?' ) ; 
4141            if  ( qsPos  !=  - 1 ) 
4242            { 
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 ) ; 
5446
5547                if  ( existingKeyPos  !=  - 1 ) 
5648                { 
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 ; 
5952
6053                    var  newUrl  =  url . Substring ( 0 ,  existingKeyPos  +  key . Length  +  1 ) 
54+                         +  "=" 
6155                        +  val . UrlEncode ( ) 
6256                        +  url . Substring ( endPos ) ; 
6357                    return  newUrl ; 
@@ -85,13 +79,18 @@ public static string SetHashParam(this string url, string key, string val)
8579            var  hPos  =  url . IndexOf ( '#' ) ; 
8680            if  ( hPos  !=  - 1 ) 
8781            { 
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+ 
8986                if  ( existingKeyPos  !=  - 1 ) 
9087                { 
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 ; 
9391
9492                    var  newUrl  =  url . Substring ( 0 ,  existingKeyPos  +  key . Length  +  1 ) 
93+                         +  "=" 
9594                        +  val . UrlEncode ( ) 
9695                        +  url . Substring ( endPos ) ; 
9796                    return  newUrl ; 
0 commit comments