You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Personally, I do not understand why the code does not rely only on http_build_query() and what it is better to decode some characters.
PostgREST needs to have the encoded version %3B of ;, otherwise it cut the string and throw an error.
curl 'http://localhost:3009/my_table?tags=ov.%7Baaa%3Bbbb%7D'# -> OK, one result
curl 'http://localhost:3009/my_table?tags=ov.%7Baaa;bbb%7D'# -> KO, error# `{"code":"22P02","details":"Unexpected end of input.","hint":null,"message":"malformed array literal: \"{aaa\""}`
Add environment VAR in postgrest: PGRST_DB_ANON_ROLE: "app_user"
ports: "3009:3000"
Run theses SQL queries:
createtablemy_tableasselect1AS id, ARRAY['aaa;bbb'] AS tags;
grantselecton my_table to app_user;
-- SQL: (operator `&&` is the same as `overlap(var1, var2)`)select*from my_table where tags && '{aaa;bbb}'; -- -> OK, one resultselect*from my_table where tags && '{aaa%3Bbbb}'; -- -> OK, empty
Characters reminder:
urlencode { is %7B
urlencode } is %7D
urlencode ; is %3B
<?phprequire'vendor/autoload.php';
$client = \Symfony\Component\HttpClient\HttpClient::create();
$query = [
'tags' => 'ov.{aaa;bbb}',
];
$request = $client->request('GET', 'http://localhost:3009/my_table', [
'query' => $query,
]);
dump(
\http_build_query($query), // good: "tags=ov.%7Baaa%3Bbbb%7D"\urlencode($query['tags']), // good: "ov.%7Baaa%3Bbbb%7D"\rawurlencode($query['tags']), // good: "ov.%7Baaa%3Bbbb%7D"\parse_url($request->getInfo()['url'], \PHP_URL_QUERY), // wrong: "tags=ov.%7Baaa;bbb%7D"// { } are still encoded but not ;
);
// Call to PostgRESTdump($request->getStatusCode()); // 400dump($request->getContent(false));
// "{"code":"22P02","details":"Unexpected end of input.","hint":null,"message":"malformed array literal: \"{aaa\""}"// Manual encoding$request = $client->request('GET', 'http://localhost:3009/my_table?tags=ov.%7Baaa%3Bbbb%7D');
dump($request->getStatusCode()); // 200dump($request->getContent(false));
// "[{"id":1,"tags":["aaa;bbb"]}]"
Possible Solution
Remove the decoding of ; in HttpClientTrait.
Additional Context
No response
The text was updated successfully, but these errors were encountered:
You don't have to let the client do the encoding: if its logic doesn't fit your need, you can encode on your side: $client->request('GET', 'http://localhost:3009/my_table?'.http_build_query($query))
encoding URIs is a quite difficult topic, with a very wide range of behaviors
You should also open an issue on pgrest to ask them to fix that behavior on their side.
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
5.4 - 7.3
Description
Hello,
Http-Client decodes semicolons
;
in https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/HttpClient/HttpClientTrait.php#L663 making this library not friendly to use with PostgREST (PgREST).Personally, I do not understand why the code does not rely only on
http_build_query()
and what it is better to decode some characters.PostgREST needs to have the encoded version
%3B
of;
, otherwise it cut the string and throw an error.How to reproduce
PGRST_DB_ANON_ROLE: "app_user"
Run theses SQL queries:
Characters reminder:
{
is%7B
}
is%7D
;
is%3B
Possible Solution
;
inHttpClientTrait
.Additional Context
No response
The text was updated successfully, but these errors were encountered: