Fixed legacy query string encoding.

This commit is contained in:
flash 2025-03-20 03:29:12 +00:00
parent 71435ba877
commit 201c6e0ab3
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
5 changed files with 34 additions and 28 deletions

View file

@ -1 +1 @@
0.2503.200311
0.2503.200328

View file

@ -55,18 +55,6 @@ class UrlEncodedFormContent implements FormContent {
++$this->position;
}
/**
* Retrieves all post fields as a query string.
*
* @param ?bool $spacesAsPlus null to use the Index url encoder, other wise whether to represent spaces as a + instead of %20 with the legacy encoder.
* @return string Query string representation of post fields.
*/
public function getParamString(?bool $spacesAsPlus = null): string {
return $spacesAsPlus === null
? HttpUri::buildQueryString($this->params)
: http_build_query($this->params, '', '&', $spacesAsPlus ? PHP_QUERY_RFC1738 : PHP_QUERY_RFC3986);
}
/**
* Parses URL encoded form params in a stream.
*

View file

@ -1,7 +1,7 @@
<?php
// HttpParameters.php
// Created: 2025-03-15
// Updated: 2025-03-15
// Updated: 2025-03-20
namespace Index\Http;
@ -84,4 +84,12 @@ interface HttpParameters {
array|int $options = 0,
mixed $default = null,
): mixed;
/**
* Retrieves parameters as a query string.
*
* @param ?bool $spacesAsPlus null to use the Index url encoder, other wise whether to represent spaces as a + instead of %20 with the legacy encoder.
* @return string Query string representation of all parameters.
*/
public function getParamString(?bool $spacesAsPlus = null): string;
}

View file

@ -1,7 +1,7 @@
<?php
// HttpParametersCommon.php
// Created: 2025-03-15
// Updated: 2025-03-15
// Updated: 2025-03-20
namespace Index\Http;
@ -99,4 +99,26 @@ trait HttpParametersCommon {
? filter_var($this->params[$name][$index], $filter, $options)
: $default;
}
/**
* Retrieves parameters as a query string.
*
* @param ?bool $spacesAsPlus null to use the Index url encoder, other wise whether to represent spaces as a + instead of %20 with the legacy encoder.
* @return string Query string representation of all parameters.
*/
public function getParamString(?bool $spacesAsPlus = null): string {
if($spacesAsPlus !== null) {
$params = [];
foreach($this->params as $name => $values)
$params[$name] = match(count($values)) {
0 => '',
1 => $values[0],
default => $values,
};
return http_build_query($params, '', '&', $spacesAsPlus ? PHP_QUERY_RFC1738 : PHP_QUERY_RFC3986);
}
return HttpUri::buildQueryString($this->params);
}
}

View file

@ -1,7 +1,7 @@
<?php
// HttpRequest.php
// Created: 2022-02-08
// Updated: 2025-03-15
// Updated: 2025-03-20
namespace Index\Http;
@ -267,18 +267,6 @@ class HttpRequest extends HttpMessage implements ServerRequestInterface, HttpPar
return $this->with(params: $query);
}
/**
* Retrieves all HTTP request query fields as a query string.
*
* @param ?bool $spacesAsPlus null to use the Index url encoder, other wise whether to represent spaces as a + instead of %20 with the legacy encoder.
* @return string Query string representation of query fields.
*/
public function getParamString(?bool $spacesAsPlus = null): string {
return $spacesAsPlus === null
? HttpUri::buildQueryString($this->params)
: http_build_query($this->params, '', '&', $spacesAsPlus ? PHP_QUERY_RFC1738 : PHP_QUERY_RFC3986);
}
/**
* @return array<string, UploadedFileInterface[]> An array tree of UploadedFileInterface instances; an empty array MUST be returned if no data is present.
*/