Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Xmlhtml needs better error messages for invalid HTML #63

Open
EvgenijM86 opened this Issue · 5 comments

3 participants

@EvgenijM86

A simple code like this <p><pre></pre></p> in a template confuses parser:

A web handler threw an exception. Details:
resources/templates/webdev-notes.tpl "resources/templates/webdev-notes.tpl" (line 16, column 27):
Pattern match failure in do expression at src/Text/XmlHtml/HTML/Parse.hs:31:5-21

If I remove <pre></pre> everything is parsed and displayed without error.

I am using snap-0.4.1 and ghc-7.0.2 on Kubuntu 10.10

@mightybyte
Owner

That is because according to the HTML 5 spec <p> elements contain phrasing content. <pre> elements are flow content, not phrasing content, so they are not allowed inside <p> tags. This is not a bug...it is a correct implementation of the spec.

@mightybyte mightybyte closed this
@mightybyte mightybyte reopened this
@mightybyte
Owner

However, on second thought, our error message is rather poor. We should definitely improve it.

@EvgenijM86

Sorry, didn't know this. I thought that might be an error because Firefox 4 open this template without any complaints (I do have HTML5 doctype).

@mightybyte
Owner

No problem. I would guess Firefox doesn't complain because of the HTML5 parsing rules that specify a consistent way to interpret invalid markup. When I put validate that markup with http://validator.w3.org/ it does give an error. But it says "No p element in scope but a p end tag seen." This is because you're not required to close a p tag. When it sees the opening pre tag, it automatically inserts a closing p tag right there.

And again, the issue here would have been obvious if our error message was better. We're working on fixing that.

@cdsmith cdsmith was assigned
@cdsmith
Collaborator

The reported error message ("Pattern match failure in do expression") no longer shows up here, for me at least. Instead, you get a Parsec "expected: long list of options" error. The error message you do get is still not 100% helpful, but at least it's not implementation focused, and given the structure of the parsing, it's difficult to see how to do better. Will keep thinking about this.

I also added an FAQ entry about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.