Menu

#1619 Unexpected POST parameters in case of malformed HTML

Latest SVN
closed
RBRi
None
1
2014-06-25
2014-06-20
No

When the HTML code of a page is malformed, HtmlUnit does a good job fixing the mess. For example, in the page below a closing div is missing in form #1:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <ul>
        <li>
            <form name="form1" action="action1" method="POST">
                <div>
                    <input name="input1" value="value1">
                    <input name="submit1" type="submit">
                <!-- closing div missing -->
            </form>
        </li>
    </ul>
    <div>
        <form name="form2" action="action2" method="POST">
            <input name="input2" value="value2">
            <input name="submit2" type="submit">
        </form>
    </div>
</body>
</html>

After HtmlUnit has loaded this page, the div is properly closed at the expected position. Cool. But when form #1 is submitted, the POST parameters will contain also input #2 from form #2.

I think that this could be a side effect of the "lost children" handling in HtmlUnit. But if the parser can fix the malformed HTML, there shouldn't be any lost children in this case. What do you think about it? Please see the attached test case to reproduce this issue.

Thanks,
J.

1 Attachments

Discussion

  • Carsten

    Carsten - 2014-06-24

    As I also had some problems with forms(see https://sourceforge.net/p/htmlunit/bugs/1610/), I looked at the HTMLParser again and found that it is indeed a problem with the lost children handling.

    In the case of synthesized end tags, the div in your case, it could happen that the variable 'formWaitingForLostChildren_' would be set to a form and not be set to null even if another form is opened.

    The attached patch includes a fix for that and a new test case.

     

    Last edit: Carsten 2014-06-24
  • RBRi

    RBRi - 2014-06-24
    • status: open --> accepted
    • assigned_to: RBRi
     
  • RBRi

    RBRi - 2014-06-24

    Have added Carstens patch. Please check and report back.

     
  • RBRi

    RBRi - 2014-06-24
    • status: accepted --> pending
     
  • Joerg Werner

    Joerg Werner - 2014-06-25

    Thanks, Carsten and Ronald. The issue is fixed now.

     
  • RBRi

    RBRi - 2014-06-25
    • status: pending --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB