From: Andrew Balholm Date: Fri, 28 Oct 2011 23:51:59 +0000 (+1100) Subject: html: adjust bookmark in "adoption agency" algorithm X-Git-Tag: weekly.2011-11-01~27 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=604e10c34d359f6522b076e488dccd7b075f4bc7;p=gostls13.git html: adjust bookmark in "adoption agency" algorithm In the adoption agency algorithm, the formatting element is sometimes removed from the list of active formatting elements and reinserted at a later index. In that case, the bookmark showing where it is to be reinserted needs to be moved, so that its position relative to its neighbors remains the same (and also so that it doesn't become out of bounds). Pass tests1.dat, test 70:
abc def ghi

jkl | | | |

| " abc " | | " def " | | " ghi " | |

| | " jkl " Also pass tests through test 76: R=nigeltao CC=golang-dev https://golang.org/cl/5322052 --- diff --git a/src/pkg/html/parse.go b/src/pkg/html/parse.go index b0348790c1..49c7a65bab 100644 --- a/src/pkg/html/parse.go +++ b/src/pkg/html/parse.go @@ -756,6 +756,10 @@ func (p *parser) inBodyEndTagFormatting(tag string) { furthestBlock.Add(clone) // Step 14. Fix up the list of active formatting elements. + if oldLoc := p.afe.index(formattingElement); oldLoc != -1 && oldLoc < bookmark { + // Move the bookmark with the rest of the list. + bookmark-- + } p.afe.remove(formattingElement) p.afe.insert(bookmark, clone) diff --git a/src/pkg/html/parse_test.go b/src/pkg/html/parse_test.go index e86a36f18a..861070d103 100644 --- a/src/pkg/html/parse_test.go +++ b/src/pkg/html/parse_test.go @@ -132,7 +132,7 @@ func TestParser(t *testing.T) { rc := make(chan io.Reader) go readDat(filename, rc) // TODO(nigeltao): Process all test cases, not just a subset. - for i := 0; i < 70; i++ { + for i := 0; i < 77; i++ { // Parse the #data section. b, err := ioutil.ReadAll(<-rc) if err != nil {