Repository navigation
Keep attribute order when removing an attribute - #645
Open
minilan677-netizen wants to merge 1 commit into
Open
minilan677-netizen wants to merge 1 commit into
minilan677-netizen wants to merge 1 commit into
Conversation
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.
Fixes #644
removeAttrdeleted an attribute by moving the last attribute into its slot and shrinking the slice. That reordered the remaining attributes, soRemoveAttr, andRemoveClass/ToggleClasswhen the class attribute ends up empty, changed the rendered HTML beyond the removed attribute (<div id="i" href="/x" class="c" title="t" data-k="v">withRemoveAttr("id")rendered as<div data-k="v" href="/x" class="c" title="t">).It now uses
slices.Delete, which keeps the other attributes in source order (as jQuery and the DOM do) and zeroes the freed slot as before.Tests:
TestRemoveAttrKeepsAttributeOrderremoves the first, a middle, the last and a missing attribute, and checks the rendered output.TestRemoveClassKeepsAttributeOrdercovers theRemoveClasspath.Both fail on master and pass with the change. The tests use
div/pbecausex/net/htmlsorts the attributes of formatting elements such as<a>while parsing.go test ./... -cover,go test -race ./...,go vet ./...(also withGOOS=windows) andgofmtpass with Go 1.27.3.