fix(parser): key style map by referenceable id only - #13
Merged
Merged
Conversation
getStyles() indexed every //kml:Style by its id attribute, including the anonymous Style elements declared inline on a Placemark. Those have no id, so they all collapsed onto the same empty string key and silently overwrote each other; the map ended up holding whichever inline style happened to come last. Inline styles cannot be reached through a styleUrl anyway, so they are now skipped and the map contains only the shared, referenceable styles. Also drops the `?: $placemarkXml->n` and `$document[0]->n` fallbacks. `n` is not a KML element and the branches were unreachable for any valid document.
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
Anonymous styles overwrite each other
getStyles()runs//kml:Styleand indexes every match by itsidattribute:That XPath also matches the
<Style>elements declared inline inside a Placemark, which have noid. Every one of them casts to'', so they all land on the same key and silently overwrite each other. A document with ten inline styles produces one entry under''holding whichever came last.Inline styles cannot be referenced through a
styleUrlin the first place, so having them in a map keyed by id serves no purpose.Dead
->nfallbacksand the matching
$document[0]->nbranch ingetDocumentName().nis not a KML element; these look like the residue of a bad find/replace. Unreachable for any valid document.Fix
Styleelements without anidingetStyles(), so the returned map contains only shared, referenceable styles.->nfallbacks.Tests
tests/StyleAndNameExtractionTest.php, against a document with two shared styles and two anonymous inline ones:main): only the twoid-bearing styles are returned, no''key, and each keeps its ownscale. Onmainthis returns 3 entries, one of which is the clobbered''bucket.->nbranches.To be explicit about scope: the
->nremoval is dead-code cleanup, not a live bug fix. The two name tests pass onmaintoo; they are there so the removal is covered, not to demonstrate a defect.Behaviour change
getStyles()no longer returns an entry under the''key. Anything relying on that key was reading a single arbitrary inline style out of however many the document contained, so this is a correction rather than a loss of capability. Worth a note in the changelog.Notes
Includes a one-line Pint fix in
loadFromString()(\Exception->Exception), sincesrc/KmlParser.phpfailspint --testonmainand this PR touches the file.