[MusicXML import] incorrect handling of instrument name with ampersand

• Nov 11, 2017 - 14:28
Reported version
S2 - Critical

I Imported a "music-xml" file and saved it as ".mscz-file". When I reopened the .mscz-file i got this error message: XML "Lesefehler in Zeile 539 Spalte 29":
The error occurs always, when there is a "&" sign in the code e.g.
Violin 1 & Oboe (Flute & Clarinet)

Attachment Size
Kantate No 147.mscx 620.92 KB


Title Program-crash Program-crash on opening a score imported from XML
Severity S4 - Minor S2 - Critical
Status (old) active needs info
Status active needs info

Please share the xml file too

Which version of MuseScore and on what OS? Several isues with & have been fixed in 2.1

The issue is in the second part, where the track name is properly escaped, but the instrument's long name contains two bare (unescaped) ampersands. Will check why this happens.

In reply to by Jojo-Schmitz


The MusicXML importer calls Part::setLongName(const QString& s) with s unmodified as read from the MusicXML part-name element. Thus s can contain any character. Via Instrument::setLongName(const QString& f) this calls StaffName(const QString& s, int p=0), which sets StaffName::_name to s.

When writing in MuseScore format, StaffName::write(Xml& xml, const char* tag) calls Xml::writeXml(const QString& name, QString s) to write StaffName::_name, where the issue occurs as writeXml expects the string to be written to be already properly xml-escaped, which it is not in this case.

This could be fixed in the MusicXML importer, but I think the structural solution would be to enforce StaffName::_name to always be properly escaped text in the StaffName class. This means adding validation to the StaffName constructor. If we don't solve it this ways, all StaffName users must be checked / changed.

Opinions anyone ?

Title Program-crash on opening a score imported from MusicXML [MusicXML import] incorrect handling of instrument name with ampersand