Skip to content

Commit

Permalink
fix #39 (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Santos Izaguirre <antoniosanct@gmail.com>
  • Loading branch information
antoniosanct committed Oct 19, 2023
1 parent d805624 commit 45c279b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
9 changes: 9 additions & 0 deletions dtd-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>coverage</id>
Expand Down
9 changes: 4 additions & 5 deletions dtd-parser/src/main/java/com/sun/xml/dtdparser/DTDParser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -1514,8 +1514,10 @@ else if (peek("#FIXED")) {
// TODO: implement this check
/// if (a.type() != Attribute.CDATA)
/// validateAttributeSyntax (a, a.defaultValue());
} else if (!peek("#IMPLIED")) {
} else if (peek("#IMPLIED")) {
attributeUse = DTDEventListener.USE_IMPLIED;
} else {
attributeUse = DTDEventListener.USE_NORMAL;

/// if (a.type() == Attribute.ID)
if (typeName == TYPE_ID) {
Expand All @@ -1535,9 +1537,6 @@ else if (peek("#FIXED")) {
// TODO: implement this check
/// if (a.type() != Attribute.CDATA)
/// validateAttributeSyntax (a, a.defaultValue());
} else {
// TODO: this looks like an fatal error.
attributeUse = DTDEventListener.USE_NORMAL;
}

if (XML_LANG.equals(attName)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package com.sun.xml.dtdparser;

import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;



public class AttributeUseTest {
Map<String, Short> attributes = new HashMap<>();

public AttributeUseTest() throws Exception {
StringBuilder dtd = new StringBuilder();
dtd.append(" <!ELEMENT root EMPTY>");
dtd.append(" <!ATTLIST root\n");
dtd.append(" normal CDATA \"default\"");
dtd.append(" implied CDATA #IMPLIED");
dtd.append(" required CDATA #REQUIRED");
dtd.append(" fixed CDATA #FIXED \"default\"");
dtd.append(" >");

DTDEventListener handler = new DTDHandlerBase() {
@Override
public void attributeDecl(String element, String name, String type, String[] enums, short use,
String defaultValue) throws SAXException {
attributes.put(name, use);
}
};
InputSource input = new InputSource(new StringReader(dtd.toString()));
DTDParser parser = new DTDParser();
parser.setDtdHandler(handler);
parser.parse(input);
}

@Test
public void testNormalAttribute() {
Assert.assertEquals(DTDEventListener.USE_NORMAL, attributes.get("normal").shortValue());
}

@Test
public void testImpliedAttribute() {
Assert.assertEquals(DTDEventListener.USE_IMPLIED, attributes.get("implied").shortValue());
}

@Test
public void testRequiredAttribute() {
Assert.assertEquals(DTDEventListener.USE_REQUIRED, attributes.get("required").shortValue());
}

@Test
public void testFixedAttribute() {
Assert.assertEquals(DTDEventListener.USE_FIXED, attributes.get("fixed").shortValue());
}
}

0 comments on commit 45c279b

Please sign in to comment.