From 8798f77484e8bbd21f759607ac031598e00d929a Mon Sep 17 00:00:00 2001 From: Maksim Gruzdev Date: Sun, 15 Mar 2026 22:47:14 +0300 Subject: [PATCH 1/4] FIX Unknown attribute: "gml:id" global attribute declarations like '' used as 'gml:id' not reconginzed --- __data__/gml_id.xsd | 18 ++++++++++++++++++ __tests__/XMLValidatior.js | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 __data__/gml_id.xsd diff --git a/__data__/gml_id.xsd b/__data__/gml_id.xsd new file mode 100644 index 0000000..4f4c625 --- /dev/null +++ b/__data__/gml_id.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + diff --git a/__tests__/XMLValidatior.js b/__tests__/XMLValidatior.js index 4e8d667..8b72070 100644 --- a/__tests__/XMLValidatior.js +++ b/__tests__/XMLValidatior.js @@ -555,5 +555,21 @@ describe ('sequence', () => { }) +}) + +describe ('gml:id attribute ref', () => { + + const xs = new XMLSchemata (Path.join (__dirname, '..', '__data__', 'gml_id.xsd')) + + test ('gml:id accepted on FunctionalZone', () => { + + new XMLParser ({xs}).process ([ + ``, + `8b2457c9-85c4-466a-a14b-b20856527718`, + ``, + ].join ('')) + + }) }) From 87780dedd65eb72e5be430680f6b310f26a49602 Mon Sep 17 00:00:00 2001 From: Maksim Gruzdev Date: Sun, 15 Mar 2026 23:00:17 +0300 Subject: [PATCH 2/4] FIX Unknown attribute: "gml:id" --- lib/validation/XMLValidationState.js | 30 ++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/validation/XMLValidationState.js b/lib/validation/XMLValidationState.js index 71c282e..2103d54 100644 --- a/lib/validation/XMLValidationState.js +++ b/lib/validation/XMLValidationState.js @@ -114,21 +114,43 @@ class XMLValidationState { } + resolveAttribute (name, attributesMap) { + + const {attributes} = this.anyType + + if (attributes.has (name)) return attributes.get (name) + + const localName = attributesMap.getLocalName (name); if (localName === name) return null + + const def = attributes.get (localName); if (!def) return null + + if (def.targetNamespace !== attributesMap.getNamespaceURI (name)) return null + + return def + + } + validateAttributes (attributesMap) { const {attributes, isAnyAttributeAllowed} = this.anyType + const matched = new Set () + for (const [name, value] of attributesMap) { - if (!attributes.has (name)) { + const def = this.resolveAttribute (name, attributesMap) + + if (!def) { if (isAnyAttributeAllowed) continue throw Error (`Unknown attribute: "${name}"`) } - - const def = attributes.get (name), {attributes: {fixed, type}} = def + + matched.add (def) + + const {attributes: {fixed, type}} = def if (typeof fixed === 'string' && value !== fixed) throw Error (`The attribute "${name}" must have the value "${fixed}", not "${value}"`) @@ -160,7 +182,7 @@ class XMLValidationState { } - for (const [name, def] of attributes) if (!attributesMap.has (name)) { + for (const [name, def] of attributes) if (!matched.has (def)) { if (def.attributes.use === 'required') throw Error (`Missing required attribute: "${name}"`) From cbd468b44a95ce05159219c33d79ee285ed0df8e Mon Sep 17 00:00:00 2001 From: Maksim Gruzdev Date: Sun, 15 Mar 2026 23:18:22 +0300 Subject: [PATCH 3/4] gml_id FIX resolveAttribute: reject bare attribute when namespace required --- __tests__/XMLValidatior.js | 11 +++++++++++ lib/validation/XMLValidationState.js | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/__tests__/XMLValidatior.js b/__tests__/XMLValidatior.js index 8b72070..49e6180 100644 --- a/__tests__/XMLValidatior.js +++ b/__tests__/XMLValidatior.js @@ -572,4 +572,15 @@ describe ('gml:id attribute ref', () => { }) + test ('bare id rejected (namespace required)', () => { + + expect (() => new XMLParser ({xs}).process ([ + ``, + `8b2457c9-85c4-466a-a14b-b20856527718`, + ``, + ].join (''))).toThrow ('Unknown attribute') + + }) + }) diff --git a/lib/validation/XMLValidationState.js b/lib/validation/XMLValidationState.js index 2103d54..d30e738 100644 --- a/lib/validation/XMLValidationState.js +++ b/lib/validation/XMLValidationState.js @@ -118,7 +118,13 @@ class XMLValidationState { const {attributes} = this.anyType - if (attributes.has (name)) return attributes.get (name) + if (attributes.has (name)) { + + const def = attributes.get (name) + + if (!def.targetNamespace || def.targetNamespace === attributesMap.getNamespaceURI (name)) return def + + } const localName = attributesMap.getLocalName (name); if (localName === name) return null From b726a6d7559784ff73fb0d27857ec3211a3b0ba1 Mon Sep 17 00:00:00 2001 From: Maksim Gruzdev Date: Sun, 15 Mar 2026 23:24:00 +0300 Subject: [PATCH 4/4] gml_id negative test++ --- __tests__/XMLValidatior.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/__tests__/XMLValidatior.js b/__tests__/XMLValidatior.js index 49e6180..056b0cc 100644 --- a/__tests__/XMLValidatior.js +++ b/__tests__/XMLValidatior.js @@ -583,4 +583,16 @@ describe ('gml:id attribute ref', () => { }) + test ('wrong namespace rejected', () => { + + expect (() => new XMLParser ({xs}).process ([ + ``, + `8b2457c9-85c4-466a-a14b-b20856527718`, + ``, + ].join (''))).toThrow ('Unknown attribute') + + }) + })