I have had a look at the change, while better than the old one it still causes problems if you use a " in a text box because you are building JSON as a string and then parsing it.
In my example code you go from a javascript object to another one there is no need for parsing so you don't run into problems with escape characters. I don't know if you are building the JSON as a string then parsing it for compatibility reasons if so you should escape any " found in the name and value. e.g. json += "\"" + e.name.replace(/\"/g,"\\\"") + "\":\"" + e.value.replace (/\"/g,"\\\"") + "\","; James On Jul 30, 6:14 pm, "marius d." <[email protected]> wrote: > James, > > I just committed the fix based on your approach. Please give it a try. > > Br's, > Marius > > On Jul 30, 4:53 pm, "marius d." <[email protected]> wrote: > > > Thank you James for your input. I hope I'll be able to look into it > > today. > > > Br's, > > Marius > > > On Jul 30, 4:42 pm, James Kearney <[email protected]> wrote: > > > > I think the current implementation of the JSON form is broken. > > > > If you put an & in a text field and try to submit it via a JSON form > > > it doesn't get handled correctly. > > > > To be precise the formToJSON function in jlift.js doesn't work, and > > > again to be more precise the params method is broken / not fit for > > > purpose. > > > > The params method (line 249) calls s.join("&") and then returns but it > > > doesn't escape the & character (it also uses = but doesn't escape > > > that). If the params function does what I think it is supposed to do > > > which is split paramters for a URL then it should really call > > > encodeURI on the values. > > > > That aside I don't think the formToJSON function should be using the > > > param function. It gets a JSON object from jQuery serializeArray makes > > > it into a string split by & and = then goes and splits based on & and > > > = again building up some JSON (as a string) then parses the JSON. Why > > > not operate on the JSON from jQuery from the start. > > > e.g. > > > > formToJSON : function(formId) > > > { > > > json = jQuery("#" + formId).serializeArray(); > > > ret = {} > > > > for (var i in json) > > > { > > > var obj = json[i] > > > > ret[obj.name] = obj.value > > > } > > > > return ret; > > > } > > > > This does work differently from before since it won't call functions > > > like params does but I don't think jQuery's serializeArray puts > > > functions in the object it returns so that is not needed. > > > > James --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---
