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

Case insensitive doctype #110

Merged
merged 2 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/com/tickaroo/tikxml/XmlReader.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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