-
Notifications
You must be signed in to change notification settings - Fork 21
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
Prefix modifier and exploded tests #27
Conversation
Good catch! Found two bugs on my implementation. |
The spec says: "A prefix modifier indicates that the variable expansion is limited to a prefix of the variable's value string." Note variable's value string. So, I think that some of those "false"s shouldn't be there... |
Hi Mark, I sent You the following tests: I think, you are worried about the following test cases: All others are clear (to me). |
@mnot Can you be a bit more precise? Does that mean that a prefix modifier is ignored for non-strings? or that they get expanded and then truncated? I always interpreted section 2.4.1
as "expanding a list or associative array (=composite value) with a prefix modifier is an error", because the standard doesn't contain any example covering this case. @fxa 👍 |
I think what @mnot is getting at is if these are negative tests case (which they are) they likely belong in the As far as the strings vs. composite values goes, I've interpreted section 2.4.1 as an error case and treating it as such in my impl. I think what @mnot is getting at is that prefix values are only every appropriate for a single value (i.e. not an array or assoc). I should note that "string" here could be a loaded term. For example, if the value of "text" were 300 and you had the following expression: I would expect the result to be "3". The end result is still a string. As far as the tests @fxa sumitted, I think it's a matter of where the tests should go. Since these are testing an error condition, these cases should be moved |
@mnot |
@fxa My understanding of the spec is that would be an error condition. It is definitely not |
@damnhandy |
ping! |
Sorry, been busy / on the road. 2.4.1 says that prefixes aren't applicable to composite values, but composite values are denoted by a "*", which these tests don't have. So, my interpretation is that you calculate the string, then truncate. Also, it's surprising (in a not good way) that you can successfully evaluate a prefix on an empty object, but not one that has values. Therefore, "{filledObject:1}" would be "c". @royfielding any comment here? |
ping! |
Any thoughts about my comments above? That's my reading still. |
Ok, let's recap:
I will withdraw the pull request and make a new one. |
The first bullet a fully agree with. The second two I do not. As @hannesg pointed out, section 2.4.1 of the spec states that:
I think that is pretty clear. With that said |
@damnhandy I now believe that I was wrong. I guess the term "composite value" doesn't refer to lists in this context but to explode modifiers ( explained one section later ). From my understanding |
Not sure. Section 2.3 makes a pretty clear definition as to what a composite value is:
I read that as a composite value is a list or associative array. As we dig further down into section 2, I don't see anything that changes what the notion of a "composite value" is or anything that changes it context. So when I see
I read
|
That’s the reason, why we are talking 7 months about that point… Von: Ryan J. McDonough [mailto:notifications@github.com] Not sure. Section 2.3 http://tools.ietf.org/html/rfc6570#section-2.3 makes a pretty clear definition as to what a composite value is: In Level 4 templates, a variable may have a composite value in the I read that as a composite value is a list or associative array. As we dig further down into section 2, I don't see anything that changes what the notion of a "composite value" is or anything that changes it context. So when I see Prefix modifiers are not applicable to variables that have composite values. I read Prefix modifiers are not applicable to variables that are list or associative arrays values. — |
Hmm, it seems that section 2.4.2 is suggesting that the |
So recapping, the second to last paragraph of section 2.3 states that a composite value is a list and associative array. It doesn't yet make mention of the explore modifier. Section 3.2.1 also suggests that there's ambiguity around what a composite value is. Going back to section 2.4.2 after reading section 3.2.1 again, I read this section as merely how the expansion process is altered with the presence of the explode modifier. With that said, given the variable values:
We all agree that this is not valid:
Nothing in the spec suggests otherwise. The crux of the issue is:
There are a few possible answers:
I'm in the BTW @fxa, I'm a little slow sometimes so sorry for the seven month lag time ;) |
@royfielding can you take a look at this please? I think we need an errata to clear this up. |
I reported an errata to the rfc at http://www.rfc-editor.org/errata_search.php?rfc=6570 |
There was a time when the draft spec allowed just about anything, including prefixes on list values, to avoid run-time error cases. However, the end result was that it caused more confusion than it is worth. Hence, the RFC says that a prefix operator is not applicable to list values, as Ryan indicated. However, a template does not reveal that a given variable is a list or a string, so the processor won't know that this is an error until fairly late in the process. The spec deliberately does not require a specific form of error handling here -- the processor can either indicate an error or treat the list value as one string and take a prefix of the entire string (not the prefix of each list value). Yes, there is a definition for composite values an explode operator that impacts composite values. I don't find that confusing. |
Hi all!
are valid results from the processor (damnHandy's #3 and #4)? |
I see. I recall older versions of the spec having a lot more features such as join operators and a means to flag a variable as being a collection of values. Obviously, @fxa, I'm now not sure how we'd be able to express both in the test suite. For implementors, you're either doing it one way or the other and not both, so having both in there could be more confusing. It may be that we drop the tests? |
Hi Ryan, { |
Hi Mark,
|
Hey, Sorry for the delay. Sounds good. |
Ok, I will rearange the tests and make a new request |
Hi there,
during refactoring of my varspec parser (cyclomatic complexity reached 20 meanwhile!) I found, that the parser misses some strange corner cases.
One was {var:011} -> my parser used the build in parseInt, which interpreted 011 as octal number and returned 9. {var:08} parsed only the 0, so the length was zero. {var:} returned a NaN. {?} returned a varspec with an empty name and so on.