1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Encode key in HTTP query.

The key also needs to be encoded (not just the value).

This is not currently an issue because none of the keys in use require encoding.
This commit is contained in:
David Steele 2023-08-29 12:35:29 -04:00
parent d24180e4da
commit 8424737697
2 changed files with 6 additions and 4 deletions

View File

@ -261,7 +261,7 @@ httpQueryRender(const HttpQuery *this, HttpQueryRenderParam param)
strCatZ(result, "&");
strCatFmt(
result, "%s=%s", strZ(key),
result, "%s=%s", strZ(httpUriEncode(key, false)),
param.redact && httpQueryRedact(this, key) ?
"<redacted>" : strZ(httpUriEncode(httpQueryGet(this, key), false)));
}

View File

@ -177,14 +177,16 @@ testRun(void)
TEST_ERROR(httpQueryNewStr(STRDEF("a=b&c")), FormatError, "invalid key/value 'c' in query 'a=b&c'");
HttpQuery *query2 = NULL;
TEST_ASSIGN(query2, httpQueryNewStr(STRDEF("?a=%2Bb&c=d%3D")), "query from string");
TEST_RESULT_STR_Z(httpQueryRenderP(query2), "a=%2Bb&c=d%3D", "render query");
TEST_ASSIGN(query2, httpQueryNewStr(STRDEF("?a%2F=%2Bb&c=d%3D")), "query from string");
TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(query2, httpQueryToLog, logBuf, sizeof(logBuf)), "httpQueryToLog");
TEST_RESULT_Z(logBuf, "{a/: '+b', c: 'd='}", "check log");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("merge queries");
TEST_RESULT_STR_Z(
httpQueryRenderP(httpQueryMerge(query, query2)), "a=%2Bb&c=d%3D&key1=value%201%3F&key2=value2a", "render merge");
httpQueryRenderP(httpQueryMerge(query, query2)), "a%2F=%2Bb&c=d%3D&key1=value%201%3F&key2=value2a", "render merge");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("free query");