mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-19 12:20:30 -06:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cf7f5f20a | ||
|
|
fb7755717b | ||
|
|
d04db56f3b | ||
|
|
48de308315 | ||
|
|
1d30834cca | ||
|
|
349d3d1c24 | ||
|
|
d842a0cc2a | ||
|
|
455a3fdc35 |
Generated
+31
-4
@@ -853,6 +853,11 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-codepage"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=254e9a409b410dc93c0e06ff66cd1e767893ac32#254e9a409b410dc93c0e06ff66cd1e767893ac32"
|
||||
|
||||
[[package]]
|
||||
name = "craft-codepage"
|
||||
version = "0.1.0"
|
||||
@@ -863,7 +868,7 @@ name = "craft-deckcraft-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=254e9a409b410dc93c0e06ff66cd1e767893ac32#254e9a409b410dc93c0e06ff66cd1e767893ac32"
|
||||
dependencies = [
|
||||
"craft-zip",
|
||||
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=254e9a409b410dc93c0e06ff66cd1e767893ac32)",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
@@ -920,13 +925,24 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-mime"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=63196e66f3033a6623eb629af95a104d26986725#63196e66f3033a6623eb629af95a104d26986725"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=254e9a409b410dc93c0e06ff66cd1e767893ac32#254e9a409b410dc93c0e06ff66cd1e767893ac32"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-codepage",
|
||||
"craft-codepage 0.1.0 (git+https://github.com/storytold/craft-libs?rev=254e9a409b410dc93c0e06ff66cd1e767893ac32)",
|
||||
"encoding_rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-opc"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10#ea24422ae9859dc5da398d0462bc87f8e02e0d10"
|
||||
dependencies = [
|
||||
"craft-xml",
|
||||
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10)",
|
||||
"log",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
@@ -941,7 +957,7 @@ name = "craft-rtf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=63196e66f3033a6623eb629af95a104d26986725#63196e66f3033a6623eb629af95a104d26986725"
|
||||
dependencies = [
|
||||
"craft-codepage",
|
||||
"craft-codepage 0.1.0 (git+https://github.com/storytold/craft-libs?rev=63196e66f3033a6623eb629af95a104d26986725)",
|
||||
"encoding_rs",
|
||||
]
|
||||
|
||||
@@ -1041,6 +1057,16 @@ dependencies = [
|
||||
"zip 9.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-zip"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10#ea24422ae9859dc5da398d0462bc87f8e02e0d10"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"thiserror 2.0.21",
|
||||
"zip 9.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.2"
|
||||
@@ -1275,6 +1301,7 @@ dependencies = [
|
||||
name = "deckcraft-pptx"
|
||||
version = "0.19.0"
|
||||
dependencies = [
|
||||
"craft-opc",
|
||||
"craft-xml",
|
||||
"deckcraft-color",
|
||||
"deckcraft-engine",
|
||||
|
||||
+4
-2
@@ -11,6 +11,8 @@ rust-version = "1.95"
|
||||
repository = "https://github.com/storytold/deckcraft"
|
||||
|
||||
[workspace.dependencies]
|
||||
# OPC part-name primitives; relationship admission stays app-local.
|
||||
craft-opc = { git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9859dc5da398d0462bc87f8e02e0d10", version = "0.1.0" }
|
||||
# XML writer primitives; parser admission and OOXML policy stay app-local.
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9859dc5da398d0462bc87f8e02e0d10", version = "0.1.0" }
|
||||
# internal
|
||||
@@ -50,8 +52,8 @@ harfrust = "0.13"
|
||||
vello_cpu = "0.2"
|
||||
vello_common = { version = "0.2", default-features = false }
|
||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "webp", "gif", "tiff", "bmp"] }
|
||||
# Base64 for command payloads (engine).
|
||||
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "63196e66f3033a6623eb629af95a104d26986725", version = "=0.1.0" }
|
||||
# Base64 for command payloads (engine); base64_compat keeps the legacy lenient decoder. Same rev as craft-deckcraft-format.
|
||||
craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "254e9a409b410dc93c0e06ff66cd1e767893ac32", version = "=0.1.0" }
|
||||
# craft-media, craft-audio and craft-video share types and stay on one rev.
|
||||
# The .deckcraft package layer (identity, manifest, member names, bounded reads); crates/format maps the presentation onto it.
|
||||
craft-deckcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "254e9a409b410dc93c0e06ff66cd1e767893ac32", version = "=0.1.0" }
|
||||
|
||||
+65
-26
@@ -612,43 +612,82 @@ pub fn base64_encode(data: &[u8]) -> String {
|
||||
|
||||
pub fn base64_decode(s: &str) -> Option<Vec<u8>> {
|
||||
let s = s.split_once("base64,").map(|(_, b)| b).unwrap_or(s);
|
||||
let mut out = Vec::with_capacity(s.len() / 4 * 3);
|
||||
let mut acc = 0u32;
|
||||
let mut bits = 0;
|
||||
let mut padded = false;
|
||||
// Preserve the command transport's admission rules before the shared legacy decoder:
|
||||
// padding ends the payload and one trailing symbol cannot encode a byte.
|
||||
let (mut symbols_mod_four, mut padded) = (0u8, false);
|
||||
for c in s.bytes() {
|
||||
let v = match c {
|
||||
b'A'..=b'Z' => c - b'A',
|
||||
b'a'..=b'z' => c - b'a' + 26,
|
||||
b'0'..=b'9' => c - b'0' + 52,
|
||||
b'+' | b'-' => 62,
|
||||
b'/' | b'_' => 63,
|
||||
b'=' => {
|
||||
padded = true;
|
||||
continue;
|
||||
match c {
|
||||
b'=' => padded = true,
|
||||
b'\n' | b'\r' | b' ' => {}
|
||||
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'+' | b'-' | b'/' | b'_' if !padded => {
|
||||
symbols_mod_four = (symbols_mod_four + 1) % 4;
|
||||
}
|
||||
b'\n' | b'\r' | b' ' => continue,
|
||||
_ => return None,
|
||||
} as u32;
|
||||
// Padding ends the payload; no further data may be decoded.
|
||||
if padded {
|
||||
return None;
|
||||
}
|
||||
acc = (acc << 6) | v;
|
||||
bits += 6;
|
||||
if bits >= 8 {
|
||||
bits -= 8;
|
||||
out.push(((acc >> bits) & 0xff) as u8);
|
||||
}
|
||||
}
|
||||
// A trailing lone Base64 character cannot encode another byte.
|
||||
(bits != 6).then_some(out)
|
||||
if symbols_mod_four == 1 {
|
||||
return None;
|
||||
}
|
||||
craft_mime::base64_compat::decode(s).ok()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// Frozen pre-cutover implementation (Brandon Thomas, with Mex's padding/tail fixes).
|
||||
fn previous_base64_decode(s: &str) -> Option<Vec<u8>> {
|
||||
let s = s.split_once("base64,").map(|(_, b)| b).unwrap_or(s);
|
||||
let mut out = Vec::with_capacity(s.len() / 4 * 3);
|
||||
let mut acc = 0u32;
|
||||
let mut bits = 0;
|
||||
let mut padded = false;
|
||||
for c in s.bytes() {
|
||||
let v = match c {
|
||||
b'A'..=b'Z' => c - b'A',
|
||||
b'a'..=b'z' => c - b'a' + 26,
|
||||
b'0'..=b'9' => c - b'0' + 52,
|
||||
b'+' | b'-' => 62,
|
||||
b'/' | b'_' => 63,
|
||||
b'=' => {
|
||||
padded = true;
|
||||
continue;
|
||||
}
|
||||
b'\n' | b'\r' | b' ' => continue,
|
||||
_ => return None,
|
||||
} as u32;
|
||||
// Padding ends the payload; no further data may be decoded.
|
||||
if padded {
|
||||
return None;
|
||||
}
|
||||
acc = (acc << 6) | v;
|
||||
bits += 6;
|
||||
if bits >= 8 {
|
||||
bits -= 8;
|
||||
out.push(((acc >> bits) & 0xff) as u8);
|
||||
}
|
||||
}
|
||||
// A trailing lone Base64 character cannot encode another byte.
|
||||
(bits != 6).then_some(out)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_decoder_preserves_command_transport_admission() {
|
||||
for text in ["", "=", "Zg== \r\n==", "Zg==A", "A", "AAAAA", "AB", "+_8=", "Z=m9v", "Zm9v\t", "Zm9v!", "data:text/plain;base64,Zm9v"] {
|
||||
assert_eq!(base64_decode(text), previous_base64_decode(text), "{text:?}");
|
||||
}
|
||||
let alphabet = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/-_= \r\n!\t";
|
||||
let mut seed = 0x1234_5678u32;
|
||||
for n in 0..50_000 {
|
||||
let mut text = String::new();
|
||||
for _ in 0..n % 65 {
|
||||
seed = seed.wrapping_mul(1_664_525).wrapping_add(1_013_904_223);
|
||||
text.push(char::from(alphabet[(seed as usize) % alphabet.len()]));
|
||||
}
|
||||
assert_eq!(base64_decode(&text), previous_base64_decode(&text), "{text:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_encoder_preserves_rfc4648_and_all_byte_remainders() {
|
||||
for (input, expected) in
|
||||
|
||||
@@ -9,6 +9,7 @@ description = "DeckCraft PPTX: Office Open XML (PresentationML/DrawingML) import
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-opc.workspace = true
|
||||
craft-xml.workspace = true
|
||||
deckcraft-model = { workspace = true }
|
||||
deckcraft-geom = { workspace = true }
|
||||
|
||||
+24
-38
@@ -255,46 +255,11 @@ pub fn sidecar_part(name: &str) -> bool {
|
||||
}
|
||||
|
||||
pub fn dir_of(part: &str) -> String {
|
||||
let p = part.trim_start_matches('/');
|
||||
match p.rfind('/') {
|
||||
Some(i) => p.get(..i).unwrap_or("").to_string(),
|
||||
None => String::new(),
|
||||
}
|
||||
craft_opc::dir_of(part).to_owned()
|
||||
}
|
||||
|
||||
pub fn file_of(part: &str) -> &str {
|
||||
part.rsplit('/').next().unwrap_or(part)
|
||||
}
|
||||
|
||||
pub fn rels_path(part: &str) -> String {
|
||||
let p = part.trim_start_matches('/');
|
||||
let dir = dir_of(p);
|
||||
let file = file_of(p);
|
||||
if dir.is_empty() { format!("_rels/{file}.rels") } else { format!("{dir}/_rels/{file}.rels") }
|
||||
}
|
||||
|
||||
fn percent_decode(s: &str) -> String {
|
||||
let b = s.as_bytes();
|
||||
let mut out = Vec::with_capacity(b.len());
|
||||
let mut i = 0;
|
||||
while i < b.len() {
|
||||
let c = b.get(i).copied().unwrap_or(0);
|
||||
if c == b'%'
|
||||
&& let Some(h) = b
|
||||
.get(i + 1..i + 3)
|
||||
.filter(|h| h.iter().all(u8::is_ascii_hexdigit))
|
||||
.and_then(|h| std::str::from_utf8(h).ok())
|
||||
.and_then(|h| u8::from_str_radix(h, 16).ok())
|
||||
{
|
||||
out.push(h);
|
||||
i += 3;
|
||||
continue;
|
||||
}
|
||||
out.push(c);
|
||||
i += 1;
|
||||
}
|
||||
String::from_utf8_lossy(&out).into_owned()
|
||||
}
|
||||
use craft_opc::percent_decode;
|
||||
pub use craft_opc::{file_of, rels_path};
|
||||
|
||||
/// Resolve a relative target against a base directory into a part name.
|
||||
pub fn resolve(base: &str, target: &str) -> String {
|
||||
@@ -469,6 +434,27 @@ impl PackageOut {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn shared_names_preserve_relationship_wire_policy() {
|
||||
for (part, dir, file, rels) in [
|
||||
("", "", "", "_rels/.rels"),
|
||||
("/", "", "", "_rels/.rels"),
|
||||
("///ppt/slides/slide1.xml", "ppt/slides", "slide1.xml", "ppt/slides/_rels/slide1.xml.rels"),
|
||||
("ppt/", "ppt", "", "ppt/_rels/.rels"),
|
||||
("é/😀.xml", "é", "😀.xml", "é/_rels/😀.xml.rels"),
|
||||
] {
|
||||
assert_eq!(dir_of(part), dir);
|
||||
assert_eq!(file_of(part), file);
|
||||
assert_eq!(rels_path(part), rels);
|
||||
}
|
||||
assert_eq!(percent_decode("a+b%20c%2Fd%23e"), "a+b c/d#e");
|
||||
assert_eq!(percent_decode("% %1 %zz %+1 %ff"), "% %1 %zz %+1 �");
|
||||
// Keep Deck's policy: strip the raw fragment first, then decode percent escapes once.
|
||||
assert_eq!(resolve("ppt/slides", "../media/a%23b.png#ignored"), "ppt/media/a#b.png");
|
||||
assert_eq!(resolve("ppt/slides", "%252e%252e/a"), "ppt/slides/%2e%2e/a");
|
||||
assert_eq!(resolve("ppt/slides", "%2e%2e/%2e%2e/%2e%2e/a"), "a");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_keeps_encoded_hash_and_strips_fragment() {
|
||||
assert_eq!(resolve("ppt/slides", "../media/a%23b.png"), "ppt/media/a#b.png");
|
||||
|
||||
Reference in New Issue
Block a user