Re: URI Template 04 Questions

On Tue, Sep 28, 2010 at 9:20 AM, Thomas Van Lenten <thomasvl@google.com> wrote:
> On Tue, Sep 28, 2010 at 8:58 AM, Thomas Van Lenten <thomasvl@google.com> wrote:
>> On Tue, Sep 28, 2010 at 5:52 AM, Mike Burrows <mjb@asplake.co.uk> wrote:
>>>
>>> Hi Thomas,
>>>
>>> On 27 September 2010 22:00, Thomas Van Lenten <thomasvl@google.com> wrote:
>>>>
>>>> I've been working on an Objective-C implementation of the 04 draft,
>>>> and ran into some questions:
>>>>
>>>>  - How should empty strings be handled when the expression has more
>>>> then one variable reference?  ('{x,empty,y}')
>>>
>>> I believe that this should expand to '1024,,768', because the empty string
>>> is a value like any other.  This particular example isn't tested but it's
>>> consistent with other tests.  For example, '{?x,y,empty}' expands to
>>> '?x=1024&y=768&empty='.
>>>
>>>>
>>>>  - Section 2.3, paragraph 4 says an variable appearing more then once
>>>> should have the same value, what if a different default is listed in
>>>> both places?  ('X{foo=val1}Y{foo=val2}Z')
>>>
>>> Mine expands this to 'Xval1Yval2Z'.  Uncontroversial I hope.
>>
>> It does sortof conflict with the statement that values should have the
>> same value through the whole expression.
>>
>>>
>>>>
>>>>  - How should empty strings within arrays be handled? (list = ( 'a',
>>>> '', 'b' ) :: '{list}' or '{?list}')
>>>>
>>>>  - How should empty strings as values in an associative array be
>>>> handled? ('keys'  = {'key1': 'val1', 'key2': '', 'key3': 'val3' } ::
>>>> '{keys}' or '{?keys}')
>>>
>>> Just more of the same I think, i.e. empty strings are not a special case.
>>
>> Right, the fact that empty arrays and associative arrays got special
>> treatment was part of why I figured I'd check to make sure they there
>> were additional expectations around empty strings within them.
>>
>>>
>>>>  - How should empty strings as keys in an associative array be
>>>> handled? ('keys'  = {'key1': 'val1', 'key2': 'val2', '': 'val3' } ::
>>>> '{keys}' or '{?keys}')
>>>
>>> Hadn't thought of that one. Is it valid/useful?  But anyway, mine doesn't
>>> treat the empty string key any differently.
>>
>> I wasn't sure, I was just trying to add more cases to cover all the
>> combinations and the results were a little odd, so I figured I'd
>> confirm that was intended and that a special case wasn't wanted.
>
> Hit send too quick.  Given:
>
>       "list"  : [ "val1", "", "val3" ],
>       "keys1"  : {"key1": "", "key2": "val2"},
>       "keys2"  : {"key1": "val1", "": "val2"}
>
> Which are correct?
>
>        "{list}" -> "val1,val3"
> or
>        "{list}" -> "val1,,val3"
>
>        "{keys1}" -> "key2,val2"
> or
>        "{keys1}" -> "key1,,key2,val2"
>
>        "{keys2}" -> "key1,val1"
> or
>        "{keys2}" -> ",val2,key1,val1"
>
> I'd actually coded the first before thinking about it.  But maybe the
> second ones are right.

After a side thread with Mike Burrows, I'm thinking the first are
probably the right values.  Here's another chunk for testing
implementations.  The most interesting cases are probably:

  '{;keysA}' -> ';key1,key2,val2'
  '{;keysA*}' -> ';key1;key2=val2'
  '{;keysA+}' -> ';keysA.key1;keysA.key2=val2'
  '{?keysA}' -> '?keysA=key1,key2,val2'
  '{?keysA*}' -> '?key1&key2=val2'
  '{?keysA+}' -> '?keysA.key1&keysA.key2=val2'

TVL
--
  "Two defaults for one variable" :
  {
    "variables": {
       "y"     : "768"
     },
     "testcases" : [
        ["1{undef=a}2{undef=b}3", "1a2b3"]
        ["0{undef}1{undef=a}2{undef}3{undef=b}4{undef}5", "01a2a3b4b5"]
     ]
  },
  "Empty strings within arrays and associative arrays" :
  {
    "variables": {
       "list"  : [ "val1", "", "val3" ],
       "keysA"  : {"key1": "", "key2": "val2"},
       "keysB"  : {"key1": "val1", "": "val2"}
     },
     "testcases" : [
        ["{list}", "val1,,val3"],
        ["{list*}", "val1,,val3"],
        ["{list+}", "list.val1,list.,list.val3"],
        ["{keysA}", "key1,,key2,val2"],
        ["{keysA*}", "key1,,key2,val2"],
        ["{keysA+}", "keysA.key1,,keysA.key2,val2"],
        ["{keysB}", ",val2,key1,val1"],
        ["{keysB*}", ",val2,key1,val1"],
        ["{keysB+}", "keysB.,val2,keysB.key1,val1"],
        ["{+list}", "val1,,val3"],
        ["{+list*}", "val1,,val3"],
        ["{+list+}", "list.val1,list.,list.val3"],
        ["{+keysA}", "key1,,key2,val2"],
        ["{+keysA*}", "key1,,key2,val2"],
        ["{+keysA+}", "keysA.key1,,keysA.key2,val2"],
        ["{+keysB}", ",val2,key1,val1"],
        ["{+keysB*}", ",val2,key1,val1"],
        ["{+keysB+}", "keysB.,val2,keysB.key1,val1"],
        ["{;list}", ";val1,,val3"],
        ["{;list*}", ";val1;;val3"],
        ["{;list+}", ";list=val1;list=;list=val3"],
        ["{;keysA}", ";key1,key2,val2"],
        ["{;keysA*}", ";key1;key2=val2"],
        ["{;keysA+}", ";keysA.key1;keysA.key2=val2"],
        ["{;keysB}", ";,val2,key1,val1"],
        ["{;keysB*}", ";=val2;key1=val1"],
        ["{;keysB+}", ";keysB.=val2;keysB.key1=val1"],
        ["{?list}", "?list=val1,,val3"],
        ["{?list*}", "?val1&&val3"],
        ["{?list+}", "?list=val1&list=&list=val3"],
        ["{?keysA}", "?keysA=key1,key2,val2"],
        ["{?keysA*}", "?key1&key2=val2"],
        ["{?keysA+}", "?keysA.key1&keysA.key2=val2"],
        ["{?keysB}", "?keysB=,val2,key1,val1"],
        ["{?keysB*}", "?=val2&key1=val1"],
        ["{?keysB+}", "?keysB.=val2&keysB.key1=val1"],
        ["{/list}", "/val1,,val3"],
        ["{/list*}", "/val1//val3"],
        ["{/list+}", "/list.val1/list./list.val3"],
        ["{/keysA}", "/key1,,key2,val2"],
        ["{/keysA*}", "/key1//key2/val2"],
        ["{/keysA+}", "/keysA.key1//keysA.key2/val2"],
        ["{/keysB}", "/,val2,key1,val1"],
        ["{/keysB*}", "//val2/key1/val1"],
        ["{/keysB+}", "/keysB./val2/keysB.key1/val1"],
        ["X{.list}", "X.val1,,val3"],
        ["X{.list*}", "X.val1..val3"],
        ["X{.list+}", "X.list.val1.list..list.val3"],
        ["X{.keysA}", "X.key1,,key2,val2"],
        ["X{.keysA*}", "X.key1..key2.val2"],
        ["X{.keysA+}", "X.keysA.key1..keysA.key2.val2"],
        ["X{.keysB}", "X.,val2,key1,val1"],
        ["X{.keysB*}", "X..val2.key1.val1"],
        ["X{.keysB+}", "X.keysB..val2.keysB.key1.val1"]
     ]
  }

Received on Tuesday, 28 September 2010 15:28:42 UTC