-
Notifications
You must be signed in to change notification settings - Fork 474
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
Mechanize #post does not retain order of fields defined #307
Comments
I just hit my head on this in phillbaker/capybara-mechanize#52. |
My analysis points to https://github.com/sparklemotion/mechanize/blob/master/lib/mechanize/form.rb#L259 as the source of the problem. Mechanize seems to go out of its way to define a custom sorting for fields (https://github.com/sparklemotion/mechanize/blob/master/lib/mechanize/form/field.rb#L39). Why is this? |
The sort in mechanize/form.rb is designed to keep the fields in the order they appear in the document and the case of a generic POST as in your example was not considered. I think this can be fixed by altering Mechanize#post to store entries with a |
I dove deeper into the '#sort' stuff and it works as intended as long as each node is backed by nokogiri. If you build up a form from hashes, the sort order is incorrect. Edit: Looks like @jasonwbarnett is doing a very similar thing with arrays. @drbrain I can change the way we're using mechanize in capybara-mechanize to rely more on nokogiri. Is this an issue you want fixed in mechanize itself? |
Another clarification. Jason and I are having the same problem from 2 different entry points. I'm building a form with code similar to |
I'm working on a project where the order of which fields are passed to the query is crucial. I was trying to build something and realized that the order was not retained. I believe it only happens when one of the fields contains bracket in it, i.e.
field name: rsargs[]
field value: anything
Code to reproduce the problem: https://gist.github.com/jasonwbarnett/249aa44a0e2b3ac078fe
I know that a lot of the code probably makes no sense (nor does the server response), but it conveys the problem quite well.
Version Info:
Mechanize/2.6.0
Ruby/1.9.3p392
The text was updated successfully, but these errors were encountered: