mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-23 07:50:58 +01:00
Merge remote-tracking branch 'origin/main' into w254
# Conflicts: # Cargo.lock # Cargo.toml
This commit is contained in:
commit
3cd7d04743
4 files changed
+41
-12
No files matched your search
Generated
+11
@@ -970,6 +970,16 @@ dependencies = [
|
||||
"wayland-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-xml"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=b6d9feed23ceae249b40593ed84a668343091627#b6d9feed23ceae249b40593ed84a668343091627"
|
||||
dependencies = [
|
||||
"quick-xml 0.41.0",
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
@@ -2735,6 +2745,7 @@ dependencies = [
|
||||
"craft-fonts-build",
|
||||
"craft-mcmat",
|
||||
"craft-texture",
|
||||
"craft-xml",
|
||||
"dds",
|
||||
"flate2",
|
||||
"gltf",
|
||||
|
||||
@@ -43,6 +43,8 @@ repository = "https://github.com/storytold/materialcraft"
|
||||
|
||||
[workspace.dependencies]
|
||||
craft-texture-dds = { package = "craft-texture", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "726ad0f8290bedb6ced60fa06200a6b574f9990d", features = ["dds"] }
|
||||
# Shared XML escaping; SBS model and serialization policy stay app-local.
|
||||
craft-xml = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "b6d9feed23ceae249b40593ed84a668343091627" }
|
||||
resvg = { version = "0.47", default-features = false }
|
||||
# internal
|
||||
materialcraft-core = { path = "crates/core" }
|
||||
|
||||
@@ -9,6 +9,7 @@ license.workspace = true
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-xml = { workspace = true }
|
||||
craft-mcmat = { workspace = true }
|
||||
materialcraft-core = { workspace = true }
|
||||
materialcraft-image = { workspace = true }
|
||||
|
||||
@@ -23,19 +23,13 @@ pub(super) fn child_value<'a>(node: XmlNode<'a, '_>, tag: &str) -> Option<&'a st
|
||||
}
|
||||
pub(super) fn xml_escape(text: &str) -> String {
|
||||
let mut out = String::with_capacity(text.len());
|
||||
for c in text.chars() {
|
||||
match c {
|
||||
'&' => out.push_str("&"),
|
||||
'<' => out.push_str("<"),
|
||||
'>' => out.push_str(">"),
|
||||
'"' => out.push_str("""),
|
||||
'\'' => out.push_str("'"),
|
||||
'\t' => out.push_str("	"),
|
||||
'\n' => out.push_str(" "),
|
||||
'\r' => out.push_str(" "),
|
||||
c if (c as u32) < 0x20 || c == '\u{fffe}' || c == '\u{ffff}' => {}
|
||||
c => out.push(c),
|
||||
// SBS historically escapes apostrophes too, although attributes are double quoted.
|
||||
// Keep that byte-level policy while sharing XML validity/attribute escaping.
|
||||
for (i, part) in text.split('\'').enumerate() {
|
||||
if i != 0 {
|
||||
out.push_str("'");
|
||||
}
|
||||
craft_xml::push_esc_attr(&mut out, part);
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -43,3 +37,24 @@ pub(super) fn is_parameters_element(xml: &str) -> bool {
|
||||
let options = roxmltree::ParsingOptions { allow_dtd: false, nodes_limit: 1_000_000 };
|
||||
xml.len() < (16 << 20) && roxmltree::Document::parse_with_options(xml, options).is_ok_and(|d| d.root_element().tag_name().name() == "parameters")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod shared_escape_tests {
|
||||
use super::xml_escape;
|
||||
|
||||
#[test]
|
||||
fn sbs_attribute_wire_spelling_is_preserved() {
|
||||
assert_eq!(xml_escape("&<>\"'\t\n\r"), "&<>"'	 ");
|
||||
assert_eq!(xml_escape("\0\u{1f}\u{fffe}\u{ffff}é😀"), "é😀");
|
||||
assert_eq!(xml_escape("''"), "''");
|
||||
assert_eq!(xml_escape(""), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn written_attribute_roundtrips_valid_unicode_and_whitespace() {
|
||||
let value = "élan 😀 ' \" & < >\t\n\r";
|
||||
let xml = format!("<value v=\"{}\"/>", xml_escape(value));
|
||||
let doc = roxmltree::Document::parse(&xml).unwrap();
|
||||
assert_eq!(doc.root_element().attribute("v"), Some(value));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user