Closed pjlammertyn closed 9 years ago
Err... no. That is not correct.
Could you post an example template and data, to make sure I get the issue correct?
var uriTemplates = require('uri-templates');
var uriTemplate = uriTemplates('{/type,ids,relatedField,relationship}{?query*}')
var url = 'http://localhost:8001/api/messages?filter[body_like]=animi%2525'
var params = uriTemplate.fromUri(url.split('?').map((part, index) => index > 0 ? decodeURIComponent(part) : part).join('?'))
console.log(params) //{ query: { 'filter[body_like]': 'animi%' } }
Why are you percent-decoding the query string before passing it to .fromUri()
?
If you skip that step, it works as expected:
var template = uriTemplates('{/type,ids,relatedField,relationship}{?query*}');
var url = 'http://localhost:8001/api/messages?filter[body_like]=animi%2525';
console.log(template.fromUri(url)); // { query: { 'filter[body_like]': 'animi%25' } }
The double-encoding error is because you're doing some munging before passing it in - what you actually end up passing in to .fromUri()
is the string: "http://localhost:8001/api/messages?filter[body_like]=animi%25"
. The template decoder does a URI-decode for the parameters (as it should) , so the result of "animi%"
is correct.
I asked, because I thought that it was a bug in fortune-json-api, but wasn't sure, even after reading the rfc6570.
is it correct that the uri encode representation of % is %2525 ? ex: ?filter[body_like]=%Ea aut nobis dolorem% uri encoded: ?filter[body_like]=%2525Ea%20aut%20nobis%20dolorem%2525