[xwiki-devs] NPE in $escapetool.url()
Hi devs, I just reported http://jira.xwiki.org/browse/XCOMMONS-494 . It seems the following generates a NPE: $escapetool.url({ 'foo': $null, 'bar': ['one', $null, 'three'], $null: 'value' }) I see 3 possible results: (1) Skip null parameter key and value bar=one&bar=three (2) Use 'null' for both the key and the value foo=null&bar=one&bar=null&bar=three&null=value (3) Use empty string for null value foo=&bar=one&bar=&bar=three&null=value I'm going to implement (1) if no one is against it. Thanks, Marius
On 11/11/2013 05:48 PM, Marius Dumitru Florea wrote:
Hi devs,
I just reported http://jira.xwiki.org/browse/XCOMMONS-494 . It seems the following generates a NPE:
$escapetool.url({ 'foo': $null, 'bar': ['one', $null, 'three'], $null: 'value' })
I see 3 possible results:
(1) Skip null parameter key and value
bar=one&bar=three
(2) Use 'null' for both the key and the value
foo=null&bar=one&bar=null&bar=three&null=value
(3) Use empty string for null value
foo=&bar=one&bar=&bar=three&null=value
I'm going to implement (1) if no one is against it.
It is legal to have parameters without values, like ?foo&bar=baz, and this signifies that a parameter is present, although it's exact value is irrelevant, it's just a marker for something. So I'd say that a null value should output just the key. If that null is part of a longer list of values, is it important to represent each null? Possibly, if the presence of nulls in the array of values is meaningful. But back on the server, reading such a parameter outputs an empty string instead of null, so it's not idempotent; we'd be replacing nulls with empty strings. Anyway, an empty string is better than a "null" string which could actually mean something. A null key, on the other hand, looks like an error. Without the proper key, the value is not that valuable (pun intended). What's it supposed to represent? So a null key should be skipped (right now it's included in the output, and it uses "null" as the key name). So, in conclusion, I vote for: (4) foo&bar=one&bar&bar=three -- Sergiu Dumitriu http://purl.org/net/sergiu
On Tue, Nov 12, 2013 at 6:44 AM, Sergiu Dumitriu <[email protected]> wrote:
On 11/11/2013 05:48 PM, Marius Dumitru Florea wrote:
Hi devs,
I just reported http://jira.xwiki.org/browse/XCOMMONS-494 . It seems the following generates a NPE:
$escapetool.url({ 'foo': $null, 'bar': ['one', $null, 'three'], $null: 'value' })
I see 3 possible results:
(1) Skip null parameter key and value
bar=one&bar=three
(2) Use 'null' for both the key and the value
foo=null&bar=one&bar=null&bar=three&null=value
(3) Use empty string for null value
foo=&bar=one&bar=&bar=three&null=value
I'm going to implement (1) if no one is against it.
It is legal to have parameters without values, like ?foo&bar=baz, and this signifies that a parameter is present, although it's exact value is irrelevant, it's just a marker for something. So I'd say that a null value should output just the key.
If that null is part of a longer list of values, is it important to represent each null? Possibly, if the presence of nulls in the array of values is meaningful. But back on the server, reading such a parameter outputs an empty string instead of null, so it's not idempotent; we'd be replacing nulls with empty strings. Anyway, an empty string is better than a "null" string which could actually mean something.
A null key, on the other hand, looks like an error. Without the proper key, the value is not that valuable (pun intended). What's it supposed to represent? So a null key should be skipped (right now it's included in the output, and it uses "null" as the key name).
So, in conclusion, I vote for:
(4) Skip null keys and use empty string for null value.
(4) foo&bar=one&bar&bar=three
Now, you can always pass '' as the value of the parameter, which is shorter than $null, if you wish to use the parameter just as a flag (i.e. present or not on the request). The use case we're dealing with is this: $escapetool.url({'key': $value}) where $value is computed previously and it can sometimes be null (either as a valid use case or because the evaluation failed). We agree about skipping null keys. You prefer using empty string for null values. I'm fine with this. Thanks, Marius
-- Sergiu Dumitriu http://purl.org/net/sergiu _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (2)
-
Marius Dumitru Florea -
Sergiu Dumitriu