Ver código fonte

Handle empty arrays when printing query params

shalvah 4 anos atrás
pai
commit
eaa820fe7c
1 arquivos alterados com 6 adições e 0 exclusões
  1. 6 0
      src/Tools/WritingUtils.php

+ 6 - 0
src/Tools/WritingUtils.php

@@ -48,6 +48,9 @@ class WritingUtils
             if (!is_array($value)) {
                 $qs .= "$paramName=" . urlencode($value) . "&";
             } else {
+                if (count($value) == 0) {
+                    continue;
+                }
                 if (array_keys($value)[0] === 0) {
                     // List query param (eg filter[]=haha should become "filter[]": "haha")
                     $qs .= "$paramName" . '[]=' . urlencode($value[0]) . '&';
@@ -80,6 +83,9 @@ class WritingUtils
                 $output .= str_repeat(" ", $spacesIndentation);
                 $output .= "$startLinesWith$quote$parameter$quote$delimiter $quote$value$quote$endLinesWith\n";
             } else {
+                if (count($value) == 0) {
+                    continue;
+                }
                 if (array_keys($value)[0] === 0) {
                     // List query param (eg filter[]=haha should become "filter[]": "haha")
                     $output .= str_repeat(" ", $spacesIndentation);