-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential bug/Unspecified behaviour #34
Comments
So package main
import (
"fmt"
"github.com/jtacoma/uritemplates"
)
func main() {
uritemplateStr := "{term}"
template, _ := uritemplates.Parse(uritemplateStr)
values := make(map[string]interface{})
values["term"] = [3]string{"foo", "bar", "bogus"}
expanded, _ := template.Expand(values)
fmt.Println(expanded)
} When run produces:
Which un-encoded is
Which seems to be pretty egregiously wrong. (It produces the same output with That said, if we modify this to use |
Ruby's Addressable has different behaviour: puts Addressable::Template.new('{term:1}').expand({
'term' => ['foo', 'bar', 'bogus'],
}).to_s prints
I'm not sure I disagree with that either. |
Meanwhile var URITemplate = require('urijs/src/URITemplate');
console.log(URITemplate('{term:1}').expand({term: ['foo', 'bar', 'bogus']})) |
Actually, this is addressed in the specification itself in 2.4.1:
With "composite values" being defined in the subsequent section (2.4.2) to be "either a list of values or an associative array of (name, value) pairs". Hence, the correct behavior would be to do what Edit: of course, unless the confusion is specifically about what "not applicable" means, i.e. whether to ignore it (current behavior as implemented in this library) or simply be explicitly unsupported (like Reading some more, the normative section on expansion implementation hints (Appendix A), the prefix modifier is only applicable if the variable value is a string; in all the "else if" options, the prefix modifier is simply not mentioned (i.e. not applicable). This non-normative "suggestion" may mean that the current implementation is sufficient. However, section 3 does not exclude the fact that what |
Let's look at a template like this:
We have two different behaviours depending upon the value used to expand
term
.A simplified version of this is simply
In other words:
All versions of
uritemplate
(anduritemplate.py
) exhibit this behaviour and the RFC does not provide clear guidance.I have not investigated how other implementations in other languages handle this, though. There do not appear to be any examples in the RFC that combine lists with length limitations.
The text was updated successfully, but these errors were encountered: