iron-ajax
iron-ajax copied to clipboard
_wwwFormUrlEncodePiece does not account for null and undefined values
_wwwFormUrlEncodePiece does not account for null and undefined values.
Expected outcome
A null or undefined value would be coalesced to an empty string during encoding.
Actual outcome
An error is thrown.
Steps to reproduce
- Put an
iron-ajax
element in the page with acontentType
ofapplication/x-www-form-urlencoded
- Set its
body
to a POJO with at least one defined key whose value is null or undefined - Attempt to invoke
generateRequest()
on theiron-ajax
element
jsbin to reproduce: https://jsbin.com/pibaregaze/edit?html,output
I'm not sure what the right way of handling this is though. I could see ignoring those key-value pairs, or encoding them as the empty string as you suggest. It's not obvious to me though that throwing an error isn't reasonable here though, as there's not a clear and unambiguous x-www-form-urlencoded
encoding for null
.
@rictic true, very good points to consider. Of course for now I have taken to doing the coalescing before hitting iron-ajax
. Maybe this is more of a documentation thing
This was in February... I opened this today:
https://github.com/PolymerElements/iron-form/issues/153
Basically, a lot of elements will have undefined
as value when they haven't been touched. Notable examples: paper-textarea
, paper-dropdown-menu
.
I can see that null
is taken care of:
https://github.com/PolymerElements/iron-ajax/blob/c6c5c80fed433502eb270a9ef9c3854bc5892d22/iron-request.html#L428-L430
However, undefined
is still an issue.
It looks like this fix:
https://github.com/PolymerElements/iron-ajax/pull/207
In response to:
https://github.com/PolymerElements/iron-ajax/issues/214
Didn't quite go far enough, and didn't include undefined
?