Skip to content

Commit

Permalink
Case insensitive doctype (#110)
Browse files Browse the repository at this point in the history
* Make doctype definition check case insensitive

* Add test for lowercase doctype definition
  • Loading branch information
Leonard Dizon authored and sockeqwe committed Oct 12, 2018
1 parent 39f2cb4 commit 0b19693
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/java/com/tickaroo/tikxml/XmlReader.java
Expand Up @@ -321,7 +321,8 @@ private boolean isCDATA() throws IOException {
* @throws IOException
*/
private boolean isDocTypeDefinition() throws IOException {
return buffer.rangeEquals(0, DOCTYPE_OPEN);
return buffer.size() >= DOCTYPE_OPEN.size() &&
buffer.snapshot(DOCTYPE_OPEN.size()).toAsciiUppercase().equals(DOCTYPE_OPEN);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/java/com/tickaroo/tikxml/XmlReaderTest.java
Expand Up @@ -1028,6 +1028,30 @@ public void xmlWithDoctypes() throws IOException {
Assert.assertFalse(reader.hasElement());
}

@Test
public void xmlWithLowercaseDoctypes() throws IOException {

String xml =
"<!doctype rootelement SYSTEM \"file.dtd\"><root\nanAttribute=\"1\"\n attributeWithWhiteSpace=\"2\" \n \t\tattributeWithTabs=\"20.2\">\n<child>Contains\nmulitlines\n</child>\n</root>";
XmlReader reader = readerFrom(xml);

reader.beginElement();
Assert.assertEquals("root", reader.nextElementName());
Assert.assertEquals("anAttribute", reader.nextAttributeName());
Assert.assertEquals(1, reader.nextAttributeValueAsInt());
Assert.assertEquals("attributeWithWhiteSpace", reader.nextAttributeName());
Assert.assertEquals("2", reader.nextAttributeValue());
Assert.assertEquals("attributeWithTabs", reader.nextAttributeName());
Assert.assertEquals(20.2, reader.nextAttributeValueAsDouble(), 0);
Assert.assertTrue(reader.hasElement());
reader.beginElement();
Assert.assertEquals("child", reader.nextElementName());
Assert.assertEquals("Contains\nmulitlines\n", reader.nextTextContent());
reader.endElement();
reader.endElement();
Assert.assertFalse(reader.hasElement());
}

@Test
public void notADocTypeDefinitionButSameDoctypeAsTag() throws IOException {

Expand Down

0 comments on commit 0b19693

Please sign in to comment.