diff --git a/go/neo/client.go b/go/neo/client.go index b7ec90e16c0c89548a24102e8eb9540b71b0f160..6242403cbcf0c2f461bfffbce9401c3675eda053 100644 --- a/go/neo/client.go +++ b/go/neo/client.go @@ -482,7 +482,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) ( // a NEOUrlInfo and the DriverOptions. If anything fails within this process // an error and an empty NEOUrlInfo are returned. func parseURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (urlinfo NEOUrlInfo, err error) { - // neo(s)://[credentials@]master1,master2,...,masterN/name?options + // neo(s)://[credentials@]master1,master2,...,masterN/name?server_options#client_options var ssl bool switch u.Scheme { @@ -536,10 +536,19 @@ func parseURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (urlinfo return NEOUrlInfo{}, err } + if len(q) != 0 { + return NEOUrlInfo{}, fmt.Errorf("invalid query: %v", q) + } + + f, err := xurl.ParseQuery(u.Fragment) + if err != nil { + return NEOUrlInfo{}, err + } + // mv readonly from URL => driver opts - readOnly, ok := q["read-only"] + readOnly, ok := f["read-only"] if ok { - delete(q, "read-only") + delete(f, "read-only") r, err := strconv.ParseBool(readOnly) if err != nil { return NEOUrlInfo{}, err @@ -550,15 +559,15 @@ func parseURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (urlinfo // pop not yet used client options // (our neo client doesn't apply their effect yet) for _, k := range []string {"compress", "cache-size", "logfile"} { - _, ok := q[k] + _, ok := f[k] if ok { - delete(q, k) + delete(f, k) log.Warningf(ctx, "TODO client doesn't support option '%q' yet", k) } } - if len(q) != 0 { - return NEOUrlInfo{}, fmt.Errorf("invalid query: %v", q) + if len(f) != 0 { + return NEOUrlInfo{}, fmt.Errorf("invalid fragment: %v", f) } if !opt.ReadOnly { diff --git a/go/neo/client_test.go b/go/neo/client_test.go index a4984f795279a54f13f131bfb700e8d8e8d7d3a4..fa5fefa9f840da68174a6f81475993ebf2630749 100644 --- a/go/neo/client_test.go +++ b/go/neo/client_test.go @@ -599,7 +599,7 @@ func TestWatch(t *testing.T) { } // TestParseURL ensures that parsing NEO URL works as expected (= following the -// scheme neo(s)://[credentials@]master1,master2,...,masterN/name?options) +// scheme neo(s)://[credentials@]master1,master2,...,masterN/name?server_options#client_options) func TestParseURL(t *testing.T) { o := zodb.DriverOptions{ReadOnly: true} i := NEOUrlInfo{} @@ -611,8 +611,8 @@ func TestParseURL(t *testing.T) { // With ssl i.netcfg = neonet.Config{CA: "ca", Cert: "cert", Key: "key"} testParseURL(t, "neos://ca=ca;cert=cert;key=key@127.0.0.1/test", &i, o, o) - // With query parameters - testParseURL(t, "neo://127.0.0.1/test?read-only=true&compress=true&logfile=n.log&cache-size=256", &i, zodb.DriverOptions{}, o) + // With fragment (= client) parameters + testParseURL(t, "neo://127.0.0.1/test#read-only=true&compress=true&logfile=n.log&cache-size=256", &i, zodb.DriverOptions{}, o) } // testParseURL tests one zurl for correctness by comparing its parsed