Skip to content

Commit

Permalink
Do normalize string-based datatype value in RelaxNG facet checking
Browse files Browse the repository at this point in the history
Original patch is from Jan Pokorný <jpokorny redhat com>
https://mail.gnome.org/archives/xml/2013-November/msg00028.html

Improve it according to reviews and add test files.
  • Loading branch information
audricschiltknecht authored and veillard committed Apr 15, 2016
1 parent 27aae65 commit cad102b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 47 deletions.
92 changes: 46 additions & 46 deletions include/libxml/schemasInternals.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,52 @@ extern "C" {

typedef enum {
XML_SCHEMAS_UNKNOWN = 0,
XML_SCHEMAS_STRING,
XML_SCHEMAS_NORMSTRING,
XML_SCHEMAS_DECIMAL,
XML_SCHEMAS_TIME,
XML_SCHEMAS_GDAY,
XML_SCHEMAS_GMONTH,
XML_SCHEMAS_GMONTHDAY,
XML_SCHEMAS_GYEAR,
XML_SCHEMAS_GYEARMONTH,
XML_SCHEMAS_DATE,
XML_SCHEMAS_DATETIME,
XML_SCHEMAS_DURATION,
XML_SCHEMAS_FLOAT,
XML_SCHEMAS_DOUBLE,
XML_SCHEMAS_BOOLEAN,
XML_SCHEMAS_TOKEN,
XML_SCHEMAS_LANGUAGE,
XML_SCHEMAS_NMTOKEN,
XML_SCHEMAS_NMTOKENS,
XML_SCHEMAS_NAME,
XML_SCHEMAS_QNAME,
XML_SCHEMAS_NCNAME,
XML_SCHEMAS_ID,
XML_SCHEMAS_IDREF,
XML_SCHEMAS_IDREFS,
XML_SCHEMAS_ENTITY,
XML_SCHEMAS_ENTITIES,
XML_SCHEMAS_NOTATION,
XML_SCHEMAS_ANYURI,
XML_SCHEMAS_INTEGER,
XML_SCHEMAS_NPINTEGER,
XML_SCHEMAS_NINTEGER,
XML_SCHEMAS_NNINTEGER,
XML_SCHEMAS_PINTEGER,
XML_SCHEMAS_INT,
XML_SCHEMAS_UINT,
XML_SCHEMAS_LONG,
XML_SCHEMAS_ULONG,
XML_SCHEMAS_SHORT,
XML_SCHEMAS_USHORT,
XML_SCHEMAS_BYTE,
XML_SCHEMAS_UBYTE,
XML_SCHEMAS_HEXBINARY,
XML_SCHEMAS_BASE64BINARY,
XML_SCHEMAS_ANYTYPE,
XML_SCHEMAS_ANYSIMPLETYPE
XML_SCHEMAS_STRING = 1,
XML_SCHEMAS_NORMSTRING = 2,
XML_SCHEMAS_DECIMAL = 3,
XML_SCHEMAS_TIME = 4,
XML_SCHEMAS_GDAY = 5,
XML_SCHEMAS_GMONTH = 6,
XML_SCHEMAS_GMONTHDAY = 7,
XML_SCHEMAS_GYEAR = 8,
XML_SCHEMAS_GYEARMONTH = 9,
XML_SCHEMAS_DATE = 10,
XML_SCHEMAS_DATETIME = 11,
XML_SCHEMAS_DURATION = 12,
XML_SCHEMAS_FLOAT = 13,
XML_SCHEMAS_DOUBLE = 14,
XML_SCHEMAS_BOOLEAN = 15,
XML_SCHEMAS_TOKEN = 16,
XML_SCHEMAS_LANGUAGE = 17,
XML_SCHEMAS_NMTOKEN = 18,
XML_SCHEMAS_NMTOKENS = 19,
XML_SCHEMAS_NAME = 20,
XML_SCHEMAS_QNAME = 21,
XML_SCHEMAS_NCNAME = 22,
XML_SCHEMAS_ID = 23,
XML_SCHEMAS_IDREF = 24,
XML_SCHEMAS_IDREFS = 25,
XML_SCHEMAS_ENTITY = 26,
XML_SCHEMAS_ENTITIES = 27,
XML_SCHEMAS_NOTATION = 28,
XML_SCHEMAS_ANYURI = 29,
XML_SCHEMAS_INTEGER = 30,
XML_SCHEMAS_NPINTEGER = 31,
XML_SCHEMAS_NINTEGER = 32,
XML_SCHEMAS_NNINTEGER = 33,
XML_SCHEMAS_PINTEGER = 34,
XML_SCHEMAS_INT = 35,
XML_SCHEMAS_UINT = 36,
XML_SCHEMAS_LONG = 37,
XML_SCHEMAS_ULONG = 38,
XML_SCHEMAS_SHORT = 39,
XML_SCHEMAS_USHORT = 40,
XML_SCHEMAS_BYTE = 41,
XML_SCHEMAS_UBYTE = 42,
XML_SCHEMAS_HEXBINARY = 43,
XML_SCHEMAS_BASE64BINARY = 44,
XML_SCHEMAS_ANYTYPE = 45,
XML_SCHEMAS_ANYSIMPLETYPE = 46
} xmlSchemaValType;

/*
Expand Down
Empty file added result/relaxng/pattern3_1
Empty file.
1 change: 1 addition & 0 deletions result/relaxng/pattern3_1.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./test/relaxng/pattern3_1.xml validates
11 changes: 11 additions & 0 deletions test/relaxng/pattern3.rng
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="test">
<data type="token">
<param name="pattern">[a-z]+</param>
</data>
</element>
</start>
</grammar>
1 change: 1 addition & 0 deletions test/relaxng/pattern3_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<test> ooo </test>
10 changes: 9 additions & 1 deletion xmlschemastypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5315,7 +5315,15 @@ xmlSchemaValidateFacetInternal(xmlSchemaFacetPtr facet,
*/
if (value == NULL)
return(-1);
ret = xmlRegexpExec(facet->regexp, value);
/*
* If string-derived type, regexp must be tested on the value space of
* the datatype.
* See https://www.w3.org/TR/xmlschema-2/#rf-pattern
*/
const int stringType = val && ((val->type >= XML_SCHEMAS_STRING && val->type <= XML_SCHEMAS_NORMSTRING)
|| (val->type >= XML_SCHEMAS_TOKEN && val->type <= XML_SCHEMAS_NCNAME));
ret = xmlRegexpExec(facet->regexp,
(stringType && val->value.str) ? val->value.str : value);
if (ret == 1)
return(0);
if (ret == 0)
Expand Down

0 comments on commit cad102b

Please sign in to comment.