Skip to content
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

Delete empty keys instead of setting to undefined #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jamilbk
Copy link

@jamilbk jamilbk commented May 20, 2013

When a serialized form is passed in with blank fields, remove the inputs that are empty. This will prevent Rails from trying to assign these fields to empty strings or nil.

When a serialized form is passed in with blank fields, remove the inputs that are empty. This will prevent Rails from trying to assign these fields to empty strings or nil.
@chrissrogers
Copy link
Owner

I am concerned that this assumed coercion would be dangerous. Deleting the key is equivalent to stating that it is not present; however, in the case you are citing, it is. Setting the value to undefined in coercion cases is more akin to what is going on in the serialized string. The key is present and accounted for, but its value is undefined.

May I suggest in your case that you perform the deletion separately, in order to achieve the feature compatibility you want with rails?

@yscumc
Copy link

yscumc commented Jun 26, 2013

I think it actually makes more sense for the value to be null if there was no equal sign. For example, I'd expect the following code to return an object with var1 = null, even without coerce, since it indicates there was no value passed.

>>> $.deparam("var1&var2=&var3=test")
Object { var3="test", var1="", var2=""}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants