Dave Oreper
2008-Feb-05 23:34 UTC
[Mechanize-users] Why does ClientForm check if self._current_form == self._global_form when closing select tags?
Mechanize: __version__ = (0, 1, 8, "b", None) # 0.1.8b Why does ClientForm.py return instead of closing the option and select tag when self._current_form == self._global_form? ClientForm.py: def end_select(self): debug("") if self._current_form is self._global_form: return if self._option is not None: self._end_option() self._select = None When there is more than one select statement outside of a form (legal html), ClientForm (improperly) raises the nested SELECTs error because the first select is never closed. This is due to the fact that during __init__ of _AbstractFormParser, self._current_form = self._global_form = self.forms[0]. When end_select is called, self._current_form == self._global_form because there are no forms. We return instead of closing the option tag and the select tag. This is a regression from __version__ = (0, 0, 12, "a", None) # 0.0.12a. Under what circumstances would we want to return instead of closing the tag? The parser works correctly if end_select is changed to: ClientForm.py: def end_select(self): debug("") if self._option is not None: self._end_option() self._select = None Example form: NOTE: This form contains valid html however upon parse, nested SELECTs error is raised. <html> <body> <select name="b" id="3"> <option class="select" value="2">XML format</option> <option class="select" value="1">CSV format</option> </select> <select name="e" id="5"> <option class="select" value="2">XML format</option> <option class="select" value="1">CSV format</option> </select> </body> </html> -DaveO -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20080205/f967eb3e/attachment-0001.html
Aaron Patterson
2008-Feb-06 04:16 UTC
[Mechanize-users] Why does ClientForm check if self._current_form == self._global_form when closing select tags?
On Tue, Feb 05, 2008 at 06:34:44PM -0500, Dave Oreper wrote:> Mechanize: __version__ = (0, 1, 8, "b", None) # 0.1.8b > > Why does ClientForm.py return instead of closing the option and select tag > when self._current_form == self._global_form? > > ClientForm.py: > def end_select(self): > debug("") > if self._current_form is self._global_form: > return > if self._option is not None: > self._end_option() > self._select = None > > When there is more than one select statement outside of a form (legal html), > ClientForm (improperly) raises the nested SELECTs error because the first > select is never closed. This is due to the fact that during __init__ of > _AbstractFormParser, self._current_form = self._global_form = self.forms[0]. > When end_select is called, self._current_form == self._global_form because > there are no forms. We return instead of closing the option tag and the > select tag. This is a regression from __version__ = (0, 0, 12, "a", None) # > 0.0.12a. > > Under what circumstances would we want to return instead of closing the tag? > > The parser works correctly if end_select is changed to: > ClientForm.py: > def end_select(self): > debug("") > if self._option is not None: > self._end_option() > self._select = None > > > > Example form: > NOTE: This form contains valid html however upon parse, nested SELECTs error > is raised. > <html> > > <body> > > <select name="b" id="3"> <option class="select" value="2">XML > format</option> > <option class="select" value="1">CSV > format</option> > > </select> > > <select name="e" > id="5"> > > <option class="select" value="2">XML format</option> <option > class="select" value="1">CSV > format</option> > > </select> > > > </body> > > </html>Try ''gem install mechanize'' -- Aaron Patterson http://tenderlovemaking.com/