Skip to content

Commit

Permalink
Add a reproducer for FasterXML#189 'Undefined ID' not thrown when val…
Browse files Browse the repository at this point in the history
…idating with SimpleNsStreamWriter
  • Loading branch information
ppalaga committed Jan 13, 2024
1 parent 50db34c commit b4abb1e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
62 changes: 62 additions & 0 deletions src/test/java/failing/TestRelaxNG189.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package failing;

import javax.xml.stream.*;

import org.codehaus.stax2.validation.*;

import wstxtest.vstream.BaseValidationTest;

/**
* A reproducer for https://github.com/FasterXML/woodstox/issues/189
* Move to {@link wstxtest.vstream.TestRelaxNG} once fixed.
*/
public class TestRelaxNG189
extends BaseValidationTest
{

/**
* Test case for testing handling ID/IDREF/IDREF attributes, using
* schema datatype library.
*/
public void testSimpleIdAttrsWriter()
throws XMLStreamException
{
final String schemaDef =
"<element xmlns='http://relaxng.org/ns/structure/1.0'"
+" datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes' name='root'>\n"
+" <oneOrMore>\n"
+" <element name='leaf'>\n"
+" <attribute name='id'><data type='ID' /></attribute>\n"
+" <optional>\n"
+" <attribute name='ref'><data type='IDREF' /></attribute>\n"
+" </optional>\n"
+" <optional>\n"
+" <attribute name='refs'><data type='IDREFS' /></attribute>\n"
+" </optional>\n"
+" </element>\n"
+" </oneOrMore>\n"
+"</element>"
;

XMLValidationSchema schema = parseRngSchema(schemaDef);

String XML;

// And then invalid one, with dangling ref
XML = "<root>"
+" <leaf id='a' ref='second' />\n"
+"</root>"
;
verifyFailure(XML, schema, "reference to undefined id",
"Undefined ID", true, false, true);

// and another one with some of refs undefined
XML = "<root>"
+" <leaf refs='this other' id='this' />\n"
+"</root>"
;
verifyFailure(XML, schema, "reference to undefined id",
"Undefined ID", true, false, true);
}

}
29 changes: 29 additions & 0 deletions src/test/java/failing/TestW3CSchema189.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package failing;

import javax.xml.stream.XMLStreamException;

import org.codehaus.stax2.validation.XMLValidationSchema;

import wstxtest.msv.TestW3CSchema;

/**
*/
public class TestW3CSchema189
extends TestW3CSchema
{

/**
* A reproducer for https://github.com/FasterXML/woodstox/issues/189
* Move to {@link TestW3CSchema} once fixed.
*/
public void testSimpleNonNsUndefinedIdWriter189() throws XMLStreamException
{
XMLValidationSchema schema = parseW3CSchema(SIMPLE_NON_NS_SCHEMA);
String XML = "<personnel><person id='a1'>"
+ "<name><family>F</family><given>G</given>"
+ "</name><link manager='m3' /></person></personnel>";
verifyFailure(XML, schema, "undefined referenced id ('m3')",
"Undefined ID 'm3'", true, false, true);
}

}
4 changes: 2 additions & 2 deletions src/test/java/wstxtest/msv/TestW3CSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class TestW3CSchema
/**
* Sample schema, using sample 'personal.xsd' found from the web
*/
final static String SIMPLE_NON_NS_SCHEMA = "<?xml version='1.0' encoding='UTF-8'?>\n"
protected final static String SIMPLE_NON_NS_SCHEMA = "<?xml version='1.0' encoding='UTF-8'?>\n"
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n"
+ "<xs:element name='personnel'>\n"
+ "<xs:complexType>\n"
Expand Down Expand Up @@ -173,7 +173,7 @@ public void testSimpleNonNsUndefinedId() throws XMLStreamException
+ "<name><family>F</family><given>G</given>"
+ "</name><link manager='m3' /></person></personnel>";
verifyFailure(XML, schema, "undefined referenced id ('m3')",
"Undefined ID 'm3'");
"Undefined ID 'm3'", true, true, false);
}

public void testSimpleDataTypes() throws XMLStreamException
Expand Down

0 comments on commit b4abb1e

Please sign in to comment.