Special characters (=|!{}[]^"~*?:\/) cause searches to fail

In GNOME Software entering searches containing some non alphanumeric characters can generate an error message. This seems to be due to the following in store/store.go:

// these characters might have special meaning on the search
// server, and don't form part of a reasonable search, so
// abort if they're included.
// "-" might also be special on the server, but it's also a
// valid part of a package name, so we let it pass
if strings.ContainsAny(searchTerm, `+=&|><!(){}[]^"~*?:\/`) {
        return nil, ErrBadQuery

The simple solution is to catch all the ErrBadQuery in gnome-software and silently ignore them. Before I do that I wanted to check if this logic is still valid - should snapd be rejecting searches like this?

To catch this reliably in GNOME Software we would need to add an error code to snapd as this is currently just a 400 error:

$ nc -C -U /run/snapd.socket
GET /v2/find?q=%3D HTTP/1.1

HTTP/1.1 400 Bad Request
Content-Type: application/json
Date: Mon, 18 Sep 2017 04:44:56 GMT
Content-Length: 90

{"type":"error","status-code":400,"status":"Bad Request","result":{"message":"bad query"}}

Thanks for this analysis and sorry for the slow turnaround on this. There is https://github.com/snapcore/snapd/pull/4428 now that will give you an error kind that you can use to distinguish this error.

1 Like

Supported in snapd-glib: