go-org-orgwiki/org/testdata/footnotes_in_headline.org
Niklas Fasching f67a251e27 html: Fix html writer footnotes (in headlines)
writer.footnotes must be a pointer as we copy the writer in nodesAsString() and
can thus end up modifying the footnotes.list slice without it being reflected in
the original writer (i.e. when the backing array of the slice changes).
2019-08-24 12:11:23 +02:00

911 B

Title 1


1

this test file just exists to reproduce a bug with footnotes in headlines - that only happens in very specific circumstances. The TLDR is:

  • HTMLWriter.footnotes should be a pointer field. I didn't notice my error as go translated my pointer-method calls on non-pointer values rather than complaining - i.e. footnotes.add() transparently gets translated to (&footnotes).add() (docs).
  • Headlines have to be htmlified twice - once for the outline and once for the headline itself. To do so we have to copy the writer
  • Copying the writer copies footnotes - which contains a map and a slice. Changes to the map will always be reflected in the original map. Changes to the slice will only be reflected if the slice doesn't grow.
  • We can thus end up with a footnote being in the mapping but not the slice - and get an index out of range error.