Encoding a URL with : and / in their queries (tags)
-
I have already created a StackOverflow question about this as having some issues around searching vms based on their tags using the api;
StackOverflow Q hereI am writing a Spring app to help us generate reports and daily checks with a per-client basis, which are tagged by the clients short hand names.
I have the basic curl query working for getting vms based on a tag however due to tags including : and / it gets a bit awkward with URI encoding.From testing (as shown in the SO question) XO will only accept the tag filter if : and / are encoded, however the URI encoder used in java strictly abides by RFC 3986 and wont allow me to encode them (found this when checking in C# as well.). Even manually encoding them breaks as the % then gets encoded as well (so a bit of fun double encoding).
Is there a way to get XO to accept un-encoded : and / or if there is another way i can pass the tags across without having to put them in the URI?
Kind Regards
Rhodri MM-D -
@Rhodderz I'm not able to reproduce the issue on my side.
I successfully filtered VMs by a
/foo
tag and was able to filter for it (tags:/^\/foo$/
) in the REST API, either by usingfilter=tags%3A%2F%5E%5C%2Ffoo%24%2F
(encoded withencodeURIComponent()
) or by usingfilter=tags:/%5E%5C/foo$/
(encoded usingencodeURI()
which does not encode/
or:
). -
Hi,
Question for @julien-f I assume
-
@Rhodderz First of all, this
filter
param is using the same syntax as xo-web and there is documentation on it: https://xen-orchestra.com/docs/manage_infrastructure.html#live-filter-searchCan you show me an example of your filter that is not properly working and I'll try it directly in xo-web?
-
@julien-f
Afternoon
The filter i am using atm the moment as a test is a tag of Staff-RMD as shown below which was generated from the UI as well (selecting the tag from the tag dropdown)
Testing via Postman, it works if everything (including the colon and forward slash) are encoded as shown:
Problem with this is alot of libraries follow the RFC3986 (1.2.3) quite strictly and will not encode the colons or forward slash (Some even throw an invalid exception). This results in a query as below which returns an internal error:
And as a test checked running it with no encoding works and i get no results (but no error)
More than happy to test other methods or workarounds. Though I have noticed I can seem to override the URIBuilder for the Java/Spring RestClient sadly.
-
@Rhodderz I'm not able to reproduce the issue on my side.
I successfully filtered VMs by a
/foo
tag and was able to filter for it (tags:/^\/foo$/
) in the REST API, either by usingfilter=tags%3A%2F%5E%5C%2Ffoo%24%2F
(encoded withencodeURIComponent()
) or by usingfilter=tags:/%5E%5C/foo$/
(encoded usingencodeURI()
which does not encode/
or:
). -
@julien-f Thanks for the help
Having a look at what you tried I had found my mistake on the testing being i removed %24 ($) and not %2F (/) when testing in postman
What appears to likley caused my confusion in the first place as well is when logging is set to Info, spring removed the trailing /, so it appeared as not there.
Setting logging to Debug shows the full URL string that it was sending including the trailing /
The other part that compounded the above is INFO throws a warning that URI will not encode certain characters, which i incorrectly followed as the source of the problem.For the final "How I confused the hell out of myself", the inital URI was actually working, however it was returning a single json object (correctly as well), however Spring silently ignored this expecting an array and just returned an empty array with it. This is fixed by setting the body from a Record to "new ParameterizedTypeReference<>() {}"
Which I did at one point however did not test again with the original working string and by this time the / was either in the wrong place, which would return no objects, or %24 was removed causing a 500 as having 2 /'s isnt accepted.Apologies for the confusion and the circle dance.
-
-
-
No worries @Rhodderz happy to know it works for you now!