Commit eee24b02 authored by Levin Zimmermann's avatar Levin Zimmermann Committed by Kirill Smelkov

go/neo/client/zurl: Drop emptry query parameters for py compatibility

During our work on 'wendelin.core' URI normalization, Kirill Smelkov
noted a inconsistency between NEO/py and NEO/go URI parser [1]: NEO/py
drops empty query options, while NEO/go preserves them. Let's fix this
inconsistency by adjusting NEO/go to NEO/py behaviour.

[1] nexedi/wendelin.core!28 (comment 212447)

/reviewed-by @kirr
/reviewed-on !9
parent 95572d6a
...@@ -503,6 +503,20 @@ func parseURL(ctx context.Context, u *url.URL) (urlinfo *urlInfo, err error) { ...@@ -503,6 +503,20 @@ func parseURL(ctx context.Context, u *url.URL) (urlinfo *urlInfo, err error) {
return nil, err return nil, err
} }
// py/compatibility: urlib.parse.parse_qs drops empty strings
// with default value for 'keep_blank_values' argument [1]. As
// we use this (with 'keep_blank_values=False') in NEO/py URI
// parser [2], we should also drop empty string query parameters in
// NEO/go to ensure the same behaviour between both implementations.
//
// [1] https://github.com/python/cpython/blob/3.12/Lib/urllib/parse.py#L703-L708
// [2] https://lab.nexedi.com/nexedi/neoppod/-/blob/3d435f55/neo/client/zodburi.py#L76
for k, v := range q {
if v == "" {
delete(q, k)
}
}
// qpop pops k from query, defaulting to $NEO_<K> if envok. // qpop pops k from query, defaulting to $NEO_<K> if envok.
qpop := func(k string, envok bool) string { qpop := func(k string, envok bool) string {
v, ok := q[k] v, ok := q[k]
......
...@@ -699,6 +699,10 @@ func TestParseURL(t *testing.T) { ...@@ -699,6 +699,10 @@ func TestParseURL(t *testing.T) {
// With query parameters // With query parameters
u = "neo://test@127.0.0.1/compress=true&logfile=n.log&cache-size=256" u = "neo://test@127.0.0.1/compress=true&logfile=n.log&cache-size=256"
testParseURL(t, u, urlInfo{}) testParseURL(t, u, urlInfo{})
// Emtpy query parameters must be ignored (if they wouldn't
// be ignored, parseURL should raise an error).
u = "neo://test@127.0.0.1?undefined-argument=&another-undefined-argument="
testParseURL(t, u, urlInfo{})
} }
// testParseURL tests one zurl for correctness by comparing its parsed // testParseURL tests one zurl for correctness by comparing its parsed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment