Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix exception in XhtmlParser with HTML5 docype
Make characters, including whitespace, after the `html' identifier in <!DOCTYPE html> be optional. Otherwise, the following errors are emitted: file.xml:2:15: whitespace expected<html xmlns="http://www.w3.org/1999/xhtml"> ^ file.xml:2:15: document must contain exactly one element And a java.lang.NullPointerException is thrown. Unfortunately, testing with Source.fromString doesn't reproduce the NullPointerException that occurs with Source.fromFile.
- Loading branch information
Showing
3 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
jvm/src/test/scala/scala/xml/parsing/XhtmlParserTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package scala.xml | ||
package parsing | ||
|
||
import scala.io.Source | ||
|
||
import org.junit.Test | ||
import org.junit.Assert.assertEquals | ||
|
||
class XhtmlParserTest { | ||
|
||
@Test | ||
def issue259: Unit = { | ||
val xml = | ||
"""|<!DOCTYPE html> | ||
|<html xmlns="http://www.w3.org/1999/xhtml"> | ||
| <head> | ||
| <meta charset="utf-8"/> | ||
| </head> | ||
| <body> | ||
| <p>Text</p> | ||
| </body> | ||
|</html>""".stripMargin | ||
|
||
val expected = <html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta charset="utf-8"/> | ||
</head> | ||
<body> | ||
<p>Text</p> | ||
</body> | ||
</html> | ||
|
||
assertEquals(expected, XhtmlParser(Source.fromString(xml)).theSeq) | ||
} | ||
|
||
@Test | ||
def html4Strict: Unit = { | ||
val xml = | ||
"""|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
| "http://www.w3.org/TR/html4/strict.dtd"> | ||
|<html> | ||
| <head> | ||
| <title>Title</title> | ||
| </head> | ||
| <body> | ||
| <p>Text</p> | ||
| </body> | ||
|</html>""".stripMargin | ||
|
||
val expected = <html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
<p>Text</p> | ||
</body> | ||
</html> | ||
|
||
assertEquals(expected, XhtmlParser(Source.fromString(xml)).theSeq) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters