Tiny example

\version "2.26.0"
\score {
  \new Staff {
    c^"AB & CD"
  }
}


   Steps to reproduce

 * Run the above tiny example with lilypond --svg testcase.ly.
 * Open the resulting SVG file in a browser to see the error.


   Expected behavior

The text “AB & CD” should be formatted in SVG as “AB & CD”. The resulting SVG should be valid.


   Actual behavior

The actual output from Lilypond is: “AB & &D”. The resulting SVG is invalid.

The exact same problem occurs with other characters that need escaping in SVG. For example, “EF < GH” is output as “EF < &lt;H” instead of the required “EF &lt; GH”.


   Analysis

The spaces between words in markup are rendered in SVG as U+200A (HAIR SPACE). This character takes 3 bytes in UTF-8 encoding. The code that tries to replace the & with &amp; runs /after/ UTF-8 encoding, counts /bytes/ to determine the index of the & character, but then uses /characters/ to determine which position to replace with &amp;. This way, the C gets replaced instead of the &.

Ideally the character replacement should occur before (or during) conversion to UTF-8.

Reply via email to