Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XhtmlParser throws java.lang.NullPointerException with valid doctype #259

Closed
mjuopperi opened this issue Sep 12, 2018 · 2 comments · Fixed by #261
Closed

XhtmlParser throws java.lang.NullPointerException with valid doctype #259

mjuopperi opened this issue Sep 12, 2018 · 2 comments · Fixed by #261

Comments

@mjuopperi
Copy link

mjuopperi commented Sep 12, 2018

Parsing the XML below with the code provided produces the following error. Adding a space before the closing > (<!DOCTYPE html >) makes it work. The doctype without the space is valid according to the HTML5 spec.

I'm fairly sure the issue is that the parser expects a space here.

file:/path/to/file.xml:2:15: whitespace expected<html xmlns="http://www.w3.org/1999/xhtml">              ^
file:/path/to/file.xml:2:15: document must contain exactly one element              ^
java.lang.NullPointerException
	at scala.xml.NodeSeq.toString(test.sc:151)
	at A$A7$.print$$$Worksheet$$$Array$$$(test.sc:38)
	at A$A7$.main(test.sc:27)
	at A$A7.main(test.sc)
	at #worksheet#.#worksheet#(test.sc)
import scala.io.Source
import scala.xml.parsing.XhtmlParser

XhtmlParser(Source.fromFile("/path/to/file.xml", "UTF-8"))
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
    </head>
    <body>
        <p>Content</p>
    </body>
</html>
@ashawley
Copy link
Member

Thanks for reporting this. Seems like it could be fixed easily enough. I worry we have enough test coverage for this code to avoid a regression. I'm also skeptical anyone uses this code to parse HTML, evidence of this bug. However, it is a sub-class of the ConstructingParser which likely has more popular usage.

@SethTisue SethTisue added the bug label Sep 21, 2018
@ashawley
Copy link
Member

Curiously, the null pointer exception doesn't occur with Source.fromString:

XhtmlParser(Source.fromString(xml))

That will make it difficult to unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants