Uploaded image for project: 'Tika'
  1. Tika
  2. TIKA-1134

ContentHandler gets ignorable whitespace for <br> tags when parsing HTML



    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: parser
    • Labels:


      I'm not very knowledgable about Tika, so it's possible iI'm missunderstanding something here, but it appears that the way Tika parses HTML to produce XHTML SAX events is missinterpreting "<br>" tags as equivilent to ignorable whitespace containing a newline. This means that clients who ask Tika to parse files, and specify their own ContentHandler to capture the character data can get sequences of run-on text w/o knowing that the "<br>" tag was present – unless they explicitly handle ignorbaleWhitespace and treat it as "real" whitespace – but this creates a catch-22 if you really do want to ignore the ignorable whitespace in the HTML markup.

      The crux of the problem seems to be:

      • instead of generating a startElement event for "br" the HtmlParser treats it as a xhtml.newline().
      • xhtml.newline() generates and ignorableWhitespace SAX event instead of a characters SAX event

      ...either one of these by themselves might be fine, but in combination they don't really make any sense. If for example an actual newline exists in the html, it comes across as part of a characters SAX event, not as ignorbale whitespace.

      Changing the newline() function to delegate to characters(...) seems to solve the problem for <br> tags in HTML, but breaks several tests – probably because the newline() function is also used to add intentionally add (synthetic) ignorableWhitespace events after elements.


        1. TIKA-1134.patch
          10 kB
          Chris M. Hostetter

          Issue Links



              • Assignee:
                hossman Chris M. Hostetter
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: