From d67a71d9dede63e4d54578b5a5a034bfec4ee4fe Mon Sep 17 00:00:00 2001 From: Brett Kail Date: Fri, 7 Aug 2026 10:06:52 +0200 Subject: [PATCH] Handle whitespace for date/time/duration types Fix https://gitlab.gnome.org/GNOME/libxml2/-/work_items/1140 See https://github.com/Arelle/Arelle/issues/2441#issuecomment-4806172135 --- result/schemas/date-whitespace_0_0.err | 1 + result/schemas/date-whitespace_0_1.err | 31 ++++++++++++++++++++++++ test/schemas/date-whitespace_0.xml | 29 ++++++++++++++++++++++ test/schemas/date-whitespace_0.xsd | 20 ++++++++++++++++ test/schemas/date-whitespace_1.xml | 33 ++++++++++++++++++++++++++ xmlschemastypes.c | 23 ++++++++++++++++-- 6 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 result/schemas/date-whitespace_0_0.err create mode 100644 result/schemas/date-whitespace_0_1.err create mode 100644 test/schemas/date-whitespace_0.xml create mode 100644 test/schemas/date-whitespace_0.xsd create mode 100644 test/schemas/date-whitespace_1.xml diff --git a/result/schemas/date-whitespace_0_0.err b/result/schemas/date-whitespace_0_0.err new file mode 100644 index 000000000..90a6f44e4 --- /dev/null +++ b/result/schemas/date-whitespace_0_0.err @@ -0,0 +1 @@ +./test/schemas/date-whitespace_0.xml validates diff --git a/result/schemas/date-whitespace_0_1.err b/result/schemas/date-whitespace_0_1.err new file mode 100644 index 000000000..5b3a92c1c --- /dev/null +++ b/result/schemas/date-whitespace_0_1.err @@ -0,0 +1,31 @@ +./test/schemas/date-whitespace_1.xml:3: Schemas validity error : Element 'date': '2000 -01-01' is not a valid value of the atomic type 'xs:date'. +./test/schemas/date-whitespace_1.xml:4: Schemas validity error : Element 'date': '2000-01 -01' is not a valid value of the atomic type 'xs:date'. +./test/schemas/date-whitespace_1.xml:5: Schemas validity error : Element 'date': '2000-01-01 Z' is not a valid value of the atomic type 'xs:date'. +./test/schemas/date-whitespace_1.xml:6: Schemas validity error : Element 'date': '2000-01-01+99:00 ' is not a valid value of the atomic type 'xs:date'. +./test/schemas/date-whitespace_1.xml:7: Schemas validity error : Element 'dateTime': '2000 -01-01T00:00:00' is not a valid value of the atomic type 'xs:dateTime'. +./test/schemas/date-whitespace_1.xml:8: Schemas validity error : Element 'dateTime': '2000-01 -01T00:00:00' is not a valid value of the atomic type 'xs:dateTime'. +./test/schemas/date-whitespace_1.xml:9: Schemas validity error : Element 'dateTime': '2000-01-01 T00:00:00' is not a valid value of the atomic type 'xs:dateTime'. +./test/schemas/date-whitespace_1.xml:10: Schemas validity error : Element 'dateTime': '2000-01-01T00 :00:00' is not a valid value of the atomic type 'xs:dateTime'. +./test/schemas/date-whitespace_1.xml:11: Schemas validity error : Element 'dateTime': '2000-01-01T00:00 :00' is not a valid value of the atomic type 'xs:dateTime'. +./test/schemas/date-whitespace_1.xml:12: Schemas validity error : Element 'dateTime': '2000-01-01T00:00:00 Z' is not a valid value of the atomic type 'xs:dateTime'. +./test/schemas/date-whitespace_1.xml:13: Schemas validity error : Element 'dateTime': '2000-01-01T00:00:00+99:00 ' is not a valid value of the atomic type 'xs:dateTime'. +./test/schemas/date-whitespace_1.xml:14: Schemas validity error : Element 'time': '00 :00:00' is not a valid value of the atomic type 'xs:time'. +./test/schemas/date-whitespace_1.xml:15: Schemas validity error : Element 'time': '00:00 :00' is not a valid value of the atomic type 'xs:time'. +./test/schemas/date-whitespace_1.xml:16: Schemas validity error : Element 'time': '00:00:00 Z' is not a valid value of the atomic type 'xs:time'. +./test/schemas/date-whitespace_1.xml:17: Schemas validity error : Element 'gYear': '2000 Z' is not a valid value of the atomic type 'xs:gYear'. +./test/schemas/date-whitespace_1.xml:18: Schemas validity error : Element 'gYearMonth': '2000 -01' is not a valid value of the atomic type 'xs:gYearMonth'. +./test/schemas/date-whitespace_1.xml:19: Schemas validity error : Element 'gYearMonth': '2000-01 Z' is not a valid value of the atomic type 'xs:gYearMonth'. +./test/schemas/date-whitespace_1.xml:20: Schemas validity error : Element 'gMonth': '--01 Z' is not a valid value of the atomic type 'xs:gMonth'. +./test/schemas/date-whitespace_1.xml:21: Schemas validity error : Element 'gMonthDay': '--01 -01' is not a valid value of the atomic type 'xs:gMonthDay'. +./test/schemas/date-whitespace_1.xml:22: Schemas validity error : Element 'gMonthDay': '--01-01 Z' is not a valid value of the atomic type 'xs:gMonthDay'. +./test/schemas/date-whitespace_1.xml:23: Schemas validity error : Element 'gDay': '---01 Z' is not a valid value of the atomic type 'xs:gDay'. +./test/schemas/date-whitespace_1.xml:24: Schemas validity error : Element 'duration': 'P 1Y' is not a valid value of the atomic type 'xs:duration'. +./test/schemas/date-whitespace_1.xml:25: Schemas validity error : Element 'duration': 'P1 Y' is not a valid value of the atomic type 'xs:duration'. +./test/schemas/date-whitespace_1.xml:26: Schemas validity error : Element 'duration': 'P1Y 1M1DT1H1M1S' is not a valid value of the atomic type 'xs:duration'. +./test/schemas/date-whitespace_1.xml:27: Schemas validity error : Element 'duration': 'P1Y1M 1DT1H1M1S' is not a valid value of the atomic type 'xs:duration'. +./test/schemas/date-whitespace_1.xml:28: Schemas validity error : Element 'duration': 'P1Y1M1D T1H1M1S' is not a valid value of the atomic type 'xs:duration'. +./test/schemas/date-whitespace_1.xml:29: Schemas validity error : Element 'duration': 'P1Y1M1DT 1H1M1S' is not a valid value of the atomic type 'xs:duration'. +./test/schemas/date-whitespace_1.xml:30: Schemas validity error : Element 'duration': 'P1Y1M1DT1 H1M1S' is not a valid value of the atomic type 'xs:duration'. +./test/schemas/date-whitespace_1.xml:31: Schemas validity error : Element 'duration': 'P1Y1M1DT1H 1M1S' is not a valid value of the atomic type 'xs:duration'. +./test/schemas/date-whitespace_1.xml:32: Schemas validity error : Element 'duration': 'P1Y1M1DT1H1M 1S' is not a valid value of the atomic type 'xs:duration'. +./test/schemas/date-whitespace_1.xml fails to validate diff --git a/test/schemas/date-whitespace_0.xml b/test/schemas/date-whitespace_0.xml new file mode 100644 index 000000000..43153fb88 --- /dev/null +++ b/test/schemas/date-whitespace_0.xml @@ -0,0 +1,29 @@ + + + 2000-01-01 + 2000-01-01 + 2000-01-01Z + 2000-01-01T00:00:00 + 2000-01-01T00:00:00 + 2000-01-01T00:00:00Z + + + + 2000 + 2000 + 2000Z + 2000-01 + 2000-01 + 2000-01Z + --01 + --01 + --01Z + --01-01 + --01-01 + --01-01Z + ---01 + ---01 + ---01Z + P1Y + P1Y + diff --git a/test/schemas/date-whitespace_0.xsd b/test/schemas/date-whitespace_0.xsd new file mode 100644 index 000000000..17d0e2202 --- /dev/null +++ b/test/schemas/date-whitespace_0.xsd @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/test/schemas/date-whitespace_1.xml b/test/schemas/date-whitespace_1.xml new file mode 100644 index 000000000..5a6d508a8 --- /dev/null +++ b/test/schemas/date-whitespace_1.xml @@ -0,0 +1,33 @@ + + + 2000 -01-01 + 2000-01 -01 + 2000-01-01 Z + 2000-01-01+99:00 + 2000 -01-01T00:00:00 + 2000-01 -01T00:00:00 + 2000-01-01 T00:00:00 + 2000-01-01T00 :00:00 + 2000-01-01T00:00 :00 + 2000-01-01T00:00:00 Z + 2000-01-01T00:00:00+99:00 + + + + 2000 Z + 2000 -01 + 2000-01 Z + --01 Z + --01 -01 + --01-01 Z + ---01 Z + P 1Y + P1 Y + P1Y 1M1DT1H1M1S + P1Y1M 1DT1H1M1S + P1Y1M1D T1H1M1S + P1Y1M1DT 1H1M1S + P1Y1M1DT1 H1M1S + P1Y1M1DT1H 1M1S + P1Y1M1DT1H1M 1S + diff --git a/xmlschemastypes.c b/xmlschemastypes.c index bbdd80b64..a5504cb31 100644 --- a/xmlschemastypes.c +++ b/xmlschemastypes.c @@ -1781,16 +1781,25 @@ xmlSchemaValidateDates (xmlSchemaValType type, xmlSchemaValPtr dt; int ret; const xmlChar *cur = dateTime; + const xmlChar *start; #define RETURN_TYPE_IF_VALID(t) \ if (IS_TZO_CHAR(*cur)) { \ ret = _xmlSchemaParseTimeZone(&(dt->value.date), &cur); \ if (ret == 0) { \ + if (collapse) \ + while IS_WSP_BLANK_CH(*cur) cur++; \ if (*cur != 0) \ goto error; \ dt->type = t; \ goto done; \ } \ + } else if (collapse && IS_WSP_BLANK_CH(*cur)) { \ + while IS_WSP_BLANK_CH(*cur) cur++; \ + if (*cur != 0) \ + goto error; \ + dt->type = t; \ + goto done; \ } if (dateTime == NULL) @@ -1799,6 +1808,8 @@ xmlSchemaValidateDates (xmlSchemaValType type, if (collapse) while IS_WSP_BLANK_CH(*cur) cur++; + start = cur; + if ((*cur != '-') && (*cur < '0') && (*cur > '9')) return 1; @@ -1889,7 +1900,7 @@ xmlSchemaValidateDates (xmlSchemaValType type, } /* fallback on date parsing */ - cur = dateTime; + cur = start; ret = _xmlSchemaParseGYear(&(dt->value.date), &cur); if (ret != 0) @@ -1929,7 +1940,8 @@ xmlSchemaValidateDates (xmlSchemaValType type, if (ret != 0) goto error; - ret = _xmlSchemaParseTimeZone(&(dt->value.date), &cur); + if (IS_TZO_CHAR(*cur)) + ret = _xmlSchemaParseTimeZone(&(dt->value.date), &cur); if (collapse) while IS_WSP_BLANK_CH(*cur) cur++; if ((ret != 0) || (*cur != 0) || (!(VALID_DATETIME((&(dt->value.date)))))) @@ -2035,6 +2047,13 @@ xmlSchemaValidateDuration (xmlSchemaTypePtr type ATTRIBUTE_UNUSED, int has_frac = 0; const xmlChar desig[] = {'Y', 'M', 'D', 'H', 'M', 'S'}; + if (collapse && IS_WSP_BLANK_CH(*cur)) { + while IS_WSP_BLANK_CH(*cur) cur++; + if (*cur != 0) + goto error; + break; + } + /* input string should be empty or invalid date/time item */ if (seq >= sizeof(desig)) goto error;