mirror of
https://github.com/storytold/soundcraft.git
synced 2026-11-16 07:12:11 +00:00
Merge pull request #1585 from storytold/extract/shared-score-xml
Use shared XML escaping for MusicXML and SVG scores
This commit is contained in:
4 files changed
+24
-7
No files matched your search
Generated
+10
@@ -1220,6 +1220,15 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10#ea24422ae9859dc5da398d0462bc87f8e02e0d10"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
@@ -4525,6 +4534,7 @@ dependencies = [
|
||||
"craft-audio",
|
||||
"craft-docpath",
|
||||
"craft-scraft-format",
|
||||
"craft-xml",
|
||||
"log",
|
||||
"proptest",
|
||||
"serde",
|
||||
|
||||
@@ -11,6 +11,7 @@ rust-version = "1.95"
|
||||
repository = "https://github.com/storytold/soundcraft"
|
||||
|
||||
[workspace.dependencies]
|
||||
craft-xml = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9859dc5da398d0462bc87f8e02e0d10" }
|
||||
craft-mime = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9859dc5da398d0462bc87f8e02e0d10" }
|
||||
# internal
|
||||
soundcraft-time = { path = "crates/time" }
|
||||
|
||||
@@ -8,6 +8,7 @@ rust-version.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-xml.workspace = true
|
||||
soundcraft-time.workspace = true
|
||||
craft-audio.workspace = true
|
||||
craft-scraft-format.workspace = true
|
||||
|
||||
@@ -273,13 +273,10 @@ fn spell(pitch: u8) -> (char, i32, i32) {
|
||||
}
|
||||
|
||||
fn xml_escape(s: &str) -> String {
|
||||
s.chars()
|
||||
.filter(|c| matches!(c, '\t' | '\n' | '\r' | '\u{20}'..='\u{D7FF}' | '\u{E000}'..='\u{FFFD}' | '\u{10000}'..='\u{10FFFF}'))
|
||||
.collect::<String>()
|
||||
.replace('&', "&")
|
||||
.replace('<', "<")
|
||||
.replace('>', ">")
|
||||
.replace('"', """)
|
||||
// Keep the score export's existing literal whitespace and quote spelling. The
|
||||
// shared attribute writer owns XML legality/escaping; only its generated
|
||||
// whitespace references are restored (input ampersands were escaped first).
|
||||
craft_xml::esc_attr(s).replace("	", "\t").replace(" ", "\n").replace(" ", "\r")
|
||||
}
|
||||
|
||||
fn note_type(units: u32) -> (&'static str, bool) {
|
||||
@@ -610,6 +607,14 @@ fn rest(o: &mut String, x: f64, y0: f64, sp: f64, units: u32) {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn shared_xml_escaping_preserves_score_bytes() {
|
||||
let input = "<&>\"'\t\n\r\0\u{1f}\u{fffe}\u{ffff}é𝄞	 ";
|
||||
assert_eq!(xml_escape(input), "<&>"'\t\n\ré𝄞&#9;&#10;&#13;");
|
||||
assert_eq!(xml_escape(""), "");
|
||||
assert_eq!(xml_escape("Already & escaped"), "Already &amp; escaped");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn split_units_uses_representable_values() {
|
||||
assert_eq!(split_units(16), vec![16]);
|
||||
|
||||
Reference in new issue
Block a user