File tree Expand file tree Collapse file tree 1 file changed +36
-10
lines changed
Expand file tree Collapse file tree 1 file changed +36
-10
lines changed Original file line number Diff line number Diff line change @@ -264,16 +264,10 @@ public function toString($raw = false, $full = true)
264264 }
265265 }
266266
267- if ($ params = $ this ->parameters ) {
268- foreach ($ params as $ p => &$ v ) {
269- // TODO: Investigate if it should be done for all (or some) other objects
270- if ($ v instanceof Horde_Url) {
271- $ v = strval ($ v );
272- }
273- }
274- unset($ v );
275-
276- $ url .= '? ' . http_build_query ($ params , "" , $ raw ? '& ' : '& ' );
267+ if ($ source = $ this ->parameters ) {
268+ $ params = [];
269+ self ::encodeParameters ($ source , '' , $ params );
270+ $ url .= '? ' . implode ($ raw ? '& ' : '& ' , $ params );
277271 }
278272
279273 if ($ this ->anchor ) {
@@ -283,6 +277,38 @@ public function toString($raw = false, $full = true)
283277 return $ url ;
284278 }
285279
280+ protected static function encodeParameters ($ source , $ prefix , &$ params )
281+ {
282+ $ index = 0 ;
283+
284+ foreach ($ source as $ p => $ v ) {
285+ if (strlen ($ prefix )) {
286+ if ($ index >= 0 && $ p !== $ index ) {
287+ $ index = -1 ;
288+ }
289+ if ($ index >= 0 ) {
290+ $ p = '' ;
291+ ++$ index ;
292+ } else {
293+ $ p = rawurlencode ($ p );
294+ }
295+ $ p = $ prefix . '[ ' . $ p . '] ' ;
296+ } else {
297+ $ p = rawurlencode ($ p );
298+ }
299+
300+ if (is_array ($ v )) {
301+ self ::encodeParameters ($ v , $ p , $ params );
302+ } else {
303+ $ v = (string ) $ v ;
304+ if (strlen ($ v )) {
305+ $ p .= '= ' . rawurlencode ($ v );
306+ }
307+ $ params [] = $ p ;
308+ }
309+ }
310+ }
311+
286312 /**
287313 * Creates the full URL string.
288314 *
You can’t perform that action at this time.
0 commit comments