From 6a03afc65df168cf60b83bc34c1b9b94c648c629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Sat, 25 Apr 2020 18:26:58 +0200 Subject: [PATCH 1/3] web plugin: support path queries by separating them with a backslash Without this change the web plugin does not support path queries as slashes are currently used for joining keywords in the QueryConverter. Moreover, flask cannot distinguish between an URL encoded and a plain '/' character during routing [0]. To work around this issue without introducing a breaking change (i.e. removing the QueryConverter) use the backslash character for path queries and convert it later on. Fixes #3566 [0]: https://github.com/pallets/flask/issues/900 --- beetsplug/web/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/beetsplug/web/__init__.py b/beetsplug/web/__init__.py index 21ff5d94e..49149772d 100644 --- a/beetsplug/web/__init__.py +++ b/beetsplug/web/__init__.py @@ -177,10 +177,11 @@ class QueryConverter(PathConverter): """ def to_python(self, value): - return value.split('/') + queries = value.split('/') + return [query.replace('\\', os.sep) for query in queries] def to_url(self, value): - return ','.join(value) + return ','.join([v.replace(os.sep, '\\') for v in value]) class EverythingConverter(PathConverter): From 57a759c8175eedabfddbd3a02e33b3af73fd13e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Sun, 26 Apr 2020 17:39:16 +0200 Subject: [PATCH 2/3] docs: document joining of paths performed by web plugin for queries --- docs/plugins/web.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/plugins/web.rst b/docs/plugins/web.rst index d416b1b7d..99214ef01 100644 --- a/docs/plugins/web.rst +++ b/docs/plugins/web.rst @@ -210,7 +210,10 @@ If the server runs UNIX, you'll need to include an extra leading slash: ``GET /item/query/querystring`` +++++++++++++++++++++++++++++++ -Returns a list of tracks matching the query. The *querystring* must be a valid query as described in :doc:`/reference/query`. :: +Returns a list of tracks matching the query. The *querystring* must be a +valid query as described in :doc:`/reference/query`. Path elements are +joined as query keywords. For example, ``/item/query/foo/bar`` will be +converted to the query ``foo,bar``. :: { "results": [ From 226d8089e1ff16687bff1731f048e8e4ba130db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Sun, 26 Apr 2020 17:45:37 +0200 Subject: [PATCH 3/3] docs: document special handling of backlash in web plugin queries --- docs/plugins/web.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/plugins/web.rst b/docs/plugins/web.rst index 99214ef01..481727475 100644 --- a/docs/plugins/web.rst +++ b/docs/plugins/web.rst @@ -213,7 +213,11 @@ If the server runs UNIX, you'll need to include an extra leading slash: Returns a list of tracks matching the query. The *querystring* must be a valid query as described in :doc:`/reference/query`. Path elements are joined as query keywords. For example, ``/item/query/foo/bar`` will be -converted to the query ``foo,bar``. :: +converted to the query ``foo,bar``. As this conflicts with using a slash +character as a path seperator in path queries, a backlash character +should be used in these queries instead. This character is converted to +the path seperator actually used by the operating system before the +query is performed. :: { "results": [