feat(validator): accept the legacy KML namespaces - #15
Merged
danielebarbaro merged 1 commit intoSep 8, 2026
Merged
Conversation
KmlValidator hardcoded the OGC 2.2 namespace and rejected everything else, so any document exported before the OGC took the format over (earth.google.com/kml/2.0, 2.1 and 2.2, still common in the wild) failed validation with "Invalid or missing KML namespace" and could not be parsed at all. The accepted namespaces are now a list, configurable through the new supported_namespaces key, and XPath is registered against the namespace the document actually declares rather than the one we assumed. That last part is what makes a 2.1 document parse end to end instead of validating and then returning no placemarks. The validator also ignored the kml-parser.namespace config entirely, even though KmlParser read it. Setting that key made every document invalid, since validation still demanded 2.2. KmlParser now passes the configured namespaces to the validator, so the key finally does what it says. KmlValidator keeps working standalone, defaulting to the known namespaces without touching the container.
danielebarbaro
merged commit Sep 8, 2026
1d06a29
into
fix/xml-parsing-and-error-handling
19 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Legacy namespaces are rejected outright
KmlValidatorhardcoded a single namespace and demanded an exact match:KML predates the OGC. Google Earth and a long tail of exporters emit
http://earth.google.com/kml/2.0,2.1and2.2, and those files are still very much in circulation. Every one of them fails withInvalid or missing KML namespaceand cannot be parsed at all.Verified before the change:
The
namespaceconfig key was inert, and setting it broke everythingKmlParser::__construct()readsconfig('kml-parser.namespace').KmlValidatordoes not, and it runs first. So the key had no effect on what was accepted, and pointing it at anything other than 2.2 made the parser reject every document: validation still demanded 2.2, and the config value was only used afterwards for XPath registration.XPath was registered against the assumed namespace
Even if validation had let a 2.1 document through,
registerXPathNamespace('kml', $this->namespace)bound the prefix to 2.2. Every//kml:Placemarkquery would have matched nothing, so the parser would have quietly returned empty arrays instead of failing.Fix
KmlValidatortakes a list of accepted namespaces, defaulting toKmlValidator::DEFAULT_NAMESPACES(OGC 2.2 plus the threeearth.google.comvariants).documentNamespace().KmlParserregisters XPath against that namespace, so queries run against what the file actually says.supported_namespaces.KmlParsermerges it with the existingnamespacekey and hands the result to the validator, sonamespacefinally does something.KmlValidatorkeeps working outside Laravel: the defaults are a class constant, and it never touches the container.Tests
tests/NamespaceSupportTest.php:earth.google.comdocuments parse end to end, placemarks and document name included — these fail onmainsupported_namespacesis acceptednamespacekey alone is enough, withsupported_namespacesemptydocumentNamespace()reports what the document declaredBreaking change
KmlValidator::$namespace(protected, string) is replaced by$namespaces(protected, array). Only relevant to anyone subclassing the validator. Worth a changelog line.Documents that were previously rejected are now accepted, which is the point, but it does mean
loadFromString()succeeds on input that used to throw.