Wicket
  1. Wicket
  2. WICKET-4511

Stack overflow when render malformed html.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.5
    • Fix Version/s: 1.5.6, 6.0.0-beta2
    • Component/s: wicket
    • Labels:
      None
    • Environment:
      windows, ubuntu. java 7, jetty 6.1.26

      Description

      Stack overflow when render malformed html.

      Please, note that </HEAD> element is inserted after </body>.

      HTML:
      <html>
      <head>
      <body>
      Malformed HTML
      </body>
      </head>
      </html>

      Java:
      package com.mycompany;

      import org.apache.wicket.markup.html.WebPage;
      public class Test1 extends WebPage

      { private static final long serialVersionUID = -4267477971499123852L; }

      Thanks.

      1. WICKET-4511.patch
        4 kB
        Andrea Del Bene
      2. console-output.txt
        87 kB
        Inaiat Henrique de Moraes

        Activity

        Hide
        Inaiat Henrique de Moraes added a comment -

        Console output.

        Show
        Inaiat Henrique de Moraes added a comment - Console output.
        Hide
        Andrea Del Bene added a comment -

        The problem is due to HtmlHeaderSectionHandler which does not identify <head> tag properly. If you look at method onComponentTag you see that variable foundHead is set to true only when closing tag </head> is encountered and not when we find the opening one.
        I've attached a patch which slightly changes the behavior of HtmlHeaderSectionHandler and solve the issue. I've tested it with all test cases without any problem.

        Show
        Andrea Del Bene added a comment - The problem is due to HtmlHeaderSectionHandler which does not identify <head> tag properly. If you look at method onComponentTag you see that variable foundHead is set to true only when closing tag </head> is encountered and not when we find the opening one. I've attached a patch which slightly changes the behavior of HtmlHeaderSectionHandler and solve the issue. I've tested it with all test cases without any problem.
        Hide
        Martin Grigorov added a comment -

        Thanks for the investigation and the patch, Andrea!

        I think we should extend HtmlHeaderSectionHandler to throw an exception if it sees <head> and <body> without </head> in between.
        Now the attached quickstart fails with StackOverflowError - not good at all but the developer goes to find what is wrong and fixes his code.
        With your fix Wicket behaves better and the developer is not notified about this problem.
        Wicket is not HTML validator but since <head> and <wicket:head> are more special I think we can add some more 'if's in this code to prevent such problem.

        Do you want to implement it and add a test ?

        Show
        Martin Grigorov added a comment - Thanks for the investigation and the patch, Andrea! I think we should extend HtmlHeaderSectionHandler to throw an exception if it sees <head> and <body> without </head> in between. Now the attached quickstart fails with StackOverflowError - not good at all but the developer goes to find what is wrong and fixes his code. With your fix Wicket behaves better and the developer is not notified about this problem. Wicket is not HTML validator but since <head> and <wicket:head> are more special I think we can add some more 'if's in this code to prevent such problem. Do you want to implement it and add a test ?
        Hide
        Andrea Del Bene added a comment -

        Yes, of course! I think should be ready by tomorrow.
        PS: Soon or later I will use IRC to speed up communication

        Show
        Andrea Del Bene added a comment - Yes, of course! I think should be ready by tomorrow. PS: Soon or later I will use IRC to speed up communication
        Hide
        Andrea Del Bene added a comment -

        Here it is. Now HtmlHeaderSectionHandler throws a MarkupException if it finds a <body> inside <head>. I've also added a test case for this issue.

        Show
        Andrea Del Bene added a comment - Here it is. Now HtmlHeaderSectionHandler throws a MarkupException if it finds a <body> inside <head>. I've also added a test case for this issue.
        Hide
        Martin Grigorov added a comment -

        Thanks again, Andrea!

        Show
        Martin Grigorov added a comment - Thanks again, Andrea!

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Inaiat Henrique de Moraes
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development