From 1e5b5f76170e7fdfc5cdc8aaa1a9ecfc6e2ca81f Mon Sep 17 00:00:00 2001 From: softwaregames1 <167585946+softwaregames1@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:17:17 +0100 Subject: [PATCH 01/35] Package: never overwrite one link's copy with another, list a missing link once (#9185) * Package: never overwrite one link's copy with another, list a missing link once Copies whose names collided were renamed to "-" once, without checking that name too: links a/x.png, b/2-x.png and c/x.png packaged the third over the second's copy, so two layers showed the same image. The name now steps until no earlier copy has it, ignoring case as macOS and Windows folders do. A missing link placed on several layers was listed once per layer. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LPBRXWMhtDUsQDdZKmt9eZ * Contributors: credit softwaregames1 by their GitHub profile name Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LPBRXWMhtDUsQDdZKmt9eZ * Package: never overwrite a file already in Links A second package into the same folder picked the same Links/ and replaced the earlier copy. A name taken by a file already there is now stepped like one taken by another link in this run. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LPBRXWMhtDUsQDdZKmt9eZ * Apply suggestion from @coderabbitai[bot] Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Claude Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- contributors/people.toml | 3 ++ crates/engine/src/print_cmds.rs | 25 ++++++++-- crates/engine/src/print_cmds/tests.rs | 66 +++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/contributors/people.toml b/contributors/people.toml index 242fb5ac80..4f345cfa18 100644 --- a/contributors/people.toml +++ b/contributors/people.toml @@ -264,3 +264,6 @@ sync_github_name = false [people.drunkeninja42] real_name = "Kushagra Sharma" + +[people.softwaregames1] +sync_github_name = true diff --git a/crates/engine/src/print_cmds.rs b/crates/engine/src/print_cmds.rs index 71efe29735..d115566a7c 100644 --- a/crates/engine/src/print_cmds.rs +++ b/crates/engine/src/print_cmds.rs @@ -1143,12 +1143,31 @@ fn package(s: &mut Session, p: &Value) -> Result { for (_, _, l) in doc.walk() { let LayerContent::Smart(so) = &l.content else { continue }; let SmartSource::Linked { path } = &so.source else { continue }; + if missing.contains(path) { + continue; + } let target = match copied.iter().find(|(src, _)| src == path) { Some((_, t)) => t.clone(), None => { - let mut fname = file_name(path); - if copied.iter().any(|(_, t)| file_name(t) == fname) { - fname = format!("{}-{}", copied.len(), fname); + // A name no earlier copy has, ignoring case (macOS and Windows folders do): a + // renamed copy can't take the name of another link either. A file already in + // Links (an earlier package into the same folder) is never overwritten. + let base = file_name(path); + let taken = |n: &str| { + copied.iter().any(|(_, t)| file_name(t).to_lowercase() == n.to_lowercase()) + || std::path::Path::new(&join(&links_dir, n)).exists() + || std::fs::read_dir(&links_dir) + .ok() + .into_iter() + .flatten() + .flatten() + .any(|entry| entry.file_name().to_string_lossy().to_lowercase() == n.to_lowercase()) + }; + let mut fname = base.clone(); + let mut k = copied.len(); + while taken(&fname) { + fname = format!("{k}-{base}"); + k += 1; } let t = join(&links_dir, &fname); // A path that is not followed is packaged as missing, like a file that is gone. diff --git a/crates/engine/src/print_cmds/tests.rs b/crates/engine/src/print_cmds/tests.rs index 43f49101a7..c4c211d16e 100644 --- a/crates/engine/src/print_cmds/tests.rs +++ b/crates/engine/src/print_cmds/tests.rs @@ -463,6 +463,72 @@ fn package_copies_links_and_relinks() { ); } +/// Links whose names collide get distinct copies, even when a renamed copy's name is already +/// another link's name (`b/2-x.png` copied before the third `x.png` would be renamed to it). +#[test] +fn package_never_overwrites_one_link_copy_with_another() { + let dir = tmp("package-collide"); + let mut s = session("rgb", 8); + let mut links = Vec::new(); + for (sub, name, colour) in [("a", "x.png", "#ff0000"), ("b", "2-x.png", "#00ff00"), ("c", "x.png", "#0000ff")] { + std::fs::create_dir_all(format!("{dir}/{sub}")).unwrap(); + let link = format!("{dir}/{sub}/{name}"); + let mut src = Session::new(); + src.execute("file.new", json!({"width": 4, "height": 4, "background": colour})).unwrap(); + crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap(); + s.execute("file.placeLinked", json!({"path": link})).unwrap(); + links.push(std::fs::read(&link).unwrap()); + } + let r = s.execute("file.package", json!({"dir": format!("{dir}/pkg")})).unwrap(); + let copies: Vec<&str> = r["links"].as_array().unwrap().iter().map(|v| v.as_str().unwrap()).collect(); + assert_eq!(copies.len(), 3); + let unique: std::collections::HashSet<&&str> = copies.iter().collect(); + assert_eq!(unique.len(), 3, "{copies:?}"); + for (copy, bytes) in copies.iter().zip(&links) { + assert_eq!(&std::fs::read(copy).unwrap(), bytes, "{copy}"); + } + let _ = std::fs::remove_dir_all(&dir); +} + +/// A second package into the same folder copies its links beside the first one's, never over them. +#[test] +fn package_keeps_files_already_in_links() { + let dir = tmp("package-again"); + let link = format!("{dir}/art.png"); + let mut src = Session::new(); + src.execute("file.new", json!({"width": 4, "height": 4, "background": "#ff0000"})).unwrap(); + crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap(); + let mut s = session("rgb", 8); + s.execute("file.placeLinked", json!({"path": link})).unwrap(); + let first = s.execute("file.package", json!({"dir": format!("{dir}/pkg")})).unwrap(); + let first = first["links"][0].as_str().unwrap().to_string(); + let kept = std::fs::read(&first).unwrap(); + let second = s.execute("file.package", json!({"dir": format!("{dir}/pkg")})).unwrap(); + let second = second["links"][0].as_str().unwrap(); + assert_ne!(second, first); + assert!(second.ends_with("Links/0-art.png"), "{second}"); + assert_eq!(std::fs::read(&first).unwrap(), kept); + assert_eq!(std::fs::read(second).unwrap(), kept); + let _ = std::fs::remove_dir_all(&dir); +} + +/// A missing link placed twice is reported once. +#[test] +fn package_lists_a_missing_link_once() { + let dir = tmp("package-missing-once"); + let link = format!("{dir}/gone.png"); + let mut src = Session::new(); + src.execute("file.new", json!({"width": 4, "height": 4})).unwrap(); + crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap(); + let mut s = session("rgb", 8); + s.execute("file.placeLinked", json!({"path": link})).unwrap(); + s.execute("file.placeLinked", json!({"path": link})).unwrap(); + std::fs::remove_file(&link).unwrap(); + let r = s.execute("file.package", json!({"dir": format!("{dir}/pkg")})).unwrap(); + assert_eq!(r["missing"], json!([link])); + let _ = std::fs::remove_dir_all(&dir); +} + #[test] fn paths_export_as_illustrator_postscript() { let mut s = session("rgb", 8); From 0b5f658fb7fb53c6de2660f4c3e1fe7e862e440a Mon Sep 17 00:00:00 2001 From: Den <103561857+ssh-den@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:17:23 +0100 Subject: [PATCH 02/35] fix(ui): match CPU grid width to physical pixels (#9199) Keep CPU grid strokes one device pixel wide at 2x display scale, matching the GPU canvas. Exercise both canvases at both display scales and U8/U16/F32 without changing upstream grid colours. --- crates/ui-egui/src/pixel_grid.rs | 3 +- crates/ui-egui/tests/it/checker_canvas.rs | 88 ++++++++++++++++++----- 2 files changed, 72 insertions(+), 19 deletions(-) diff --git a/crates/ui-egui/src/pixel_grid.rs b/crates/ui-egui/src/pixel_grid.rs index 4ec68ccae4..e7a565ae2a 100644 --- a/crates/ui-egui/src/pixel_grid.rs +++ b/crates/ui-egui/src/pixel_grid.rs @@ -176,9 +176,10 @@ pub fn paint(app: &mut PhotocraftApp, painter: &Painter, xf: &ViewXform, idx: us cache.grid = Some(GridLines::build(&doc, revision, preview_key, cache_region(visible, doc.bounds()))); } let Some(grid) = &cache.grid else { return }; + let width = 1.0 / painter.ctx().pixels_per_point(); for s in &grid.segs { let (a, b) = (xf.to_screen(s.from[0] as f32, s.from[1] as f32), xf.to_screen(s.to[0] as f32, s.to[1] as f32)); - painter.line_segment([a, b], Stroke::new(1.0, s.color)); + painter.line_segment([a, b], Stroke::new(width, s.color)); } } diff --git a/crates/ui-egui/tests/it/checker_canvas.rs b/crates/ui-egui/tests/it/checker_canvas.rs index 3c5e061afd..513d277abf 100644 --- a/crates/ui-egui/tests/it/checker_canvas.rs +++ b/crates/ui-egui/tests/it/checker_canvas.rs @@ -20,8 +20,12 @@ fn harness() -> Option { /// The app with the GPU canvas (`gpu`), or without it: the CPU fallback path. fn harness_with(gpu: bool) -> Option { + harness_with_scale(gpu, 1.0) +} + +fn harness_with_scale(gpu: bool, ppp: f32) -> Option { let built = std::panic::catch_unwind(|| { - egui_kittest::Harness::builder().with_size(egui::vec2(1400.0, 800.0)).with_pixels_per_point(1.0).with_max_steps(64).wgpu().build_eframe(|cc| { + egui_kittest::Harness::builder().with_size(egui::vec2(1400.0, 800.0)).with_pixels_per_point(ppp).with_max_steps(64).wgpu().build_eframe(|cc| { PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); if let Some(rs) = cc.wgpu_render_state.as_ref().filter(|_| gpu) { @@ -111,13 +115,15 @@ fn render_on(h: &mut Harness, gpu: bool, zoom: f32, doc: u32, black: bool, grid: let rendered = h.render().expect("render"); let (width, height) = (rendered.width(), rendered.height()); let img = Shot { w: width, px: rendered.into_raw() }; + if black { + // View geometry also works on scaled displays, independently of grid colour. + let origin = photocraft_ui_egui::canvas::ViewXform::active(h.state()).expect("view").to_screen(0.0, 0.0) * h.ctx.pixels_per_point(); + return (img, origin.x.round() as u32, origin.y.round() as u32, (doc as f32 * zoom).round() as u32); + } let r = h.state().last_canvas_rect; let (cx, cy) = (r.center().x as u32, r.center().y as u32); - // Black fill is 0 (64 on a grid line), the pasteboard is 39. - // (Two CPU grid lines crossing blend twice: about 112.) - let on_doc = |p: [u8; 4]| if black { p[0] < 12 || (58..=70).contains(&p[0]) || (105..=120).contains(&p[0]) } else { is_checker_grey(p) }; - let (x0, w) = longest_run((0..width).map(|x| on_doc(img.at(x, cy)))); - let (y0, hgt) = longest_run((0..height).map(|y| on_doc(img.at(cx, y)))); + let (x0, w) = longest_run((0..width).map(|x| is_checker_grey(img.at(x, cy)))); + let (y0, hgt) = longest_run((0..height).map(|y| is_checker_grey(img.at(cx, y)))); let doc_px = (doc as f32 * zoom).round() as i64; assert!((w as i64 - doc_px).abs() <= 1 && (hgt as i64 - doc_px).abs() <= 1, "zoom {zoom}: found a {w}x{hgt} document, want {doc_px}"); (img, x0 as u32, y0 as u32, w as u32) @@ -210,18 +216,20 @@ fn pixel_grid_is_not_drawn_over_empty_checker() { #[test] fn cpu_pixel_grid_shows_above_500_percent_over_content() { let _gpu = photocraft_testkit::gpu_lock(); - let Some(mut h) = harness_with(false) else { return }; - h.run_steps(4); - let (flat, x0, y0, _) = render_on(&mut h, false, 5.0, 48, true, true); - assert!(lit_columns(&flat, x0, y0 + 20, 100).is_empty(), "no grid at 500%"); - for zoom in [6.0f32, 8.0, 12.0] { - let (img, x0, y0, _) = render_on(&mut h, false, zoom, 48, true, true); - let y = y0 + (zoom * 3.5) as u32; - let lit = lit_columns(&img, x0, y, (zoom * 10.0) as u32); - assert_eq!(lit.len(), 10, "zoom {zoom}: grid columns {lit:?}"); - assert!(lit.windows(2).all(|p| p[1] - p[0] == zoom as u32), "zoom {zoom}: spacing of {lit:?}"); - let v = img.at(x0 + lit[2], y)[0]; - assert!((60..=68).contains(&v), "zoom {zoom}: a grid line over black is {v}, want about 64"); + for ppp in [1.0, 2.0] { + let Some(mut h) = harness_with_scale(false, ppp) else { return }; + h.run_steps(4); + let (flat, x0, y0, _) = render_on(&mut h, false, 5.0, 48, true, true); + assert!(lit_columns(&flat, x0, y0 + 20, 100).is_empty(), "no grid at 500%"); + for zoom in [6.0f32, 8.0, 12.0] { + let (img, x0, y0, _) = render_on(&mut h, false, zoom, 48, true, true); + let y = y0 + (zoom * 3.5) as u32; + let lit = lit_columns(&img, x0, y, (zoom * 10.0) as u32); + assert_eq!(lit.len(), 10, "scale {ppp}, zoom {zoom}: one physical pixel per line, columns {lit:?}"); + assert!(lit.windows(2).all(|p| p[1] - p[0] == zoom as u32), "zoom {zoom}: spacing of {lit:?}"); + let v = img.at(x0 + lit[2], y)[0]; + assert!((60..=68).contains(&v), "zoom {zoom}: a grid line over black is {v}, want about 64"); + } } } @@ -295,3 +303,47 @@ fn pixel_grid_does_not_flip_colour_across_mid_tones() { assert!(c >= 20, "grey {grey:#04x}: grid line differs from its pixel by only {c} levels"); } } + +#[test] +fn pixel_grid_is_solid_and_visible_on_white_and_black_at_both_display_scales() { + let _gpu = photocraft_testkit::gpu_lock(); + use photocraft_color::{ColorMode, PixelFormat, SampleType}; + use photocraft_doc::{Document, Layer, LayerContent, Size}; + use photocraft_geom::Rect; + use photocraft_raster::Surface; + + for gpu in [true, false] { + for ppp in [1.0, 2.0] { + let Some(mut h) = harness_with_scale(gpu, ppp) else { return }; + for depth in [SampleType::U8, SampleType::U16, SampleType::F32] { + for v in [0.0, 1.0] { + let mut doc = Document::new("grid contrast", Size::new(32, 16), ColorMode::Rgb, depth); + let mut surface = Surface::new(PixelFormat::new(ColorMode::Rgb, depth, true)); + surface.fill_rect(Rect::new(0, 0, 32, 16), &[v, v, v, 1.0]); + doc.layers.push(Layer::new("opaque", LayerContent::Raster(surface))); + let app = h.state_mut(); + app.session.add_document(doc, None); + app.sync_views(); + app.ui.view.show.pixel_grid = true; + for zoom in [7.119, 8.0, 22.825] { + control(&mut h, "ui.set", json!({"zoom": zoom, "center": [16.0, 8.0]})); + assert_eq!(h.state().perf.gpu, gpu); + let img = h.render().expect("render opaque grid"); + let center = h.state().last_canvas_rect.center() * ppp; + let x0 = center.x - 16.0 * zoom; + let y = (center.y + 3.25 * zoom).floor() as u32; + for x in 2..30 { + let edge = (x0 + x as f32 * zoom).floor() as u32; + for sy in y..y + 3 { + let inside = img.get_pixel((x0 + (x as f32 + 0.5) * zoom).floor() as u32, sy)[0]; + assert_eq!(inside, (v * 255.0) as u8); + let contrast = (edge - 1..=edge + 1).map(|sx| img.get_pixel(sx, sy)[0].abs_diff(inside)).max().expect("line"); + assert!(contrast >= 28, "{gpu:?}/{depth:?}, scale {ppp}, zoom {zoom}, fill {v}, ({x}, {sy}): invisible grid ({contrast})"); + } + } + } + } + } + } + } +} From 41c8a9e215bc0495ba7a32c7991176627debaeea Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 25 Oct 2026 15:17:29 +0100 Subject: [PATCH 03/35] =?UTF-8?q?Image=20Rotation=20=E2=80=BA=20Arbitrary?= =?UTF-8?q?=20turns=20unlinked=20layer=20masks=20(#9201)=20(#9203)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Image Rotation › Arbitrary turns unlinked layer masks (#9201) Free Transform's helper moves a pixel mask only when it is linked, so rotating the whole image (and a turned crop) left unlinked masks of non-Background layers in place. Warp them too, recursively into groups, as every other canvas operation does. Co-Authored-By: Claude Opus 5.5 * Tests: the unlinked mask also turns the right way at 90° (#9201) Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/engine/src/mode_cmds.rs | 20 +++++++++++ crates/engine/src/mode_cmds/tests.rs | 53 ++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/crates/engine/src/mode_cmds.rs b/crates/engine/src/mode_cmds.rs index 180f940e91..413b768846 100644 --- a/crates/engine/src/mode_cmds.rs +++ b/crates/engine/src/mode_cmds.rs @@ -123,6 +123,8 @@ pub(crate) fn rotate_arbitrary(s: &mut Session, p: &Value) -> Result { } else { // Rotating the whole image moves locked layers too, including inside groups. with_released_movement_locks(l, |l| crate::transform_cmds::transform_layer(None, photocraft_doc::Locks::default(), l, &h, Some(a), interp))?; + // Free Transform moves only linked masks; the whole image turns them all (#9201). + warp_unlinked_masks(l, &h, interp)?; } // What Free Transform leaves alone: unlinked vector masks, gradient angles, artboards… crate::canvas_geom::transform_layer_geometry(l, &a, false, dpi); @@ -142,6 +144,24 @@ pub(crate) fn rotate_arbitrary(s: &mut Session, p: &Value) -> Result { Ok(json!({"width": size.width, "height": size.height})) } +/// Warps the unlinked pixel masks of `l` and its descendants, which [`transform_layer`] leaves in +/// place. +/// +/// [`transform_layer`]: crate::transform_cmds::transform_layer +fn warp_unlinked_masks(l: &mut Layer, h: &Homography, interp: Interp) -> Result<()> { + if let Some(m) = l.mask.as_mut() + && !m.linked + { + m.surface = crate::transform_cmds::warp_gray(&m.surface, h, interp)?; + } + if let LayerContent::Group(g) = &mut l.content { + for c in &mut g.children { + warp_unlinked_masks(c, h, interp)?; + } + } + Ok(()) +} + /// Runs `f` with movement locks (`position` and `all`) temporarily released on `l` and all its /// descendants, so canvas-wide rotation moves every layer, then restores each lock. fn with_released_movement_locks(l: &mut Layer, f: impl FnOnce(&mut Layer) -> Result) -> Result { diff --git a/crates/engine/src/mode_cmds/tests.rs b/crates/engine/src/mode_cmds/tests.rs index 84d816a349..21836ff5ae 100644 --- a/crates/engine/src/mode_cmds/tests.rs +++ b/crates/engine/src/mode_cmds/tests.rs @@ -144,6 +144,59 @@ fn rotate_arbitrary_rotates_grouped_locked_children_and_preserves_lock() { assert_eq!(photocraft_compose::flatten(&d_arb).px, photocraft_compose::flatten(d_cw).px); } +/// Rotating the whole image turns every layer mask, linked or not, as Rotate 180° does (#9201). +#[test] +fn rotate_arbitrary_turns_unlinked_layer_masks() { + for depth in [8, 16] { + for grouped in [false, true] { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 40, "height": 30, "depth": depth, "background": "white"})).unwrap(); + s.execute("layer.new.layer", json!({"name": "Paint"})).unwrap(); + s.execute("select.rect", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); + s.execute("edit.fill", json!({"color": "#ff0000"})).unwrap(); + s.execute("layer.layerMask.revealSelection", json!({})).unwrap(); + s.execute("layer.layerMask.linked", json!({"linked": false})).unwrap(); + let id = s.active().unwrap().active_layer.unwrap(); + if grouped { + s.execute("layer.groupLayers", json!({})).unwrap(); + } + let mask = |s: &Session| doc(s).layer(id).unwrap().mask.clone().unwrap(); + let base = s.active().unwrap().doc.clone(); + s.execute("image.rotation.arbitrary", json!({"angle": 180, "interpolation": "nearest"})).unwrap(); + let m = mask(&s); + assert!(!m.linked); + let at = |x, y| m.surface.sample_channel(x, y, 0); + assert!(at(34, 24) > 0.9, "{depth}-bit, grouped {grouped}: the mask turned with its layer"); + assert!(at(4, 4) < 0.1, "{depth}-bit, grouped {grouped}: nothing left at the old place"); + // Rotate 180° and a crop turned by 180° over the whole canvas give the same mask. + for (id_, p) in [("image.imageRotation.180", json!({})), ("image.crop", json!({"x": 0, "y": 0, "width": 40, "height": 30, "angle": 180}))] { + s.active_mut().unwrap().doc = base.clone(); + s.execute(id_, p).unwrap(); + let turned = mask(&s); + for y in 0..30 { + for x in 0..40 { + let (a, b) = (at(x, y), turned.surface.sample_channel(x, y, 0)); + assert!((a - b).abs() < 1e-3, "{id_}, {depth}-bit, grouped {grouped}: ({x},{y}) {a} vs {b}"); + } + } + } + // 90° pins the direction too (180° is its own inverse). + s.active_mut().unwrap().doc = base.clone(); + s.execute("image.rotation.arbitrary", json!({"angle": 90, "interpolation": "nearest"})).unwrap(); + let arbitrary = mask(&s); + s.active_mut().unwrap().doc = base.clone(); + s.execute("image.imageRotation.90cw", json!({})).unwrap(); + let turned = mask(&s); + for y in 0..40 { + for x in 0..30 { + let (a, b) = (arbitrary.surface.sample_channel(x, y, 0), turned.surface.sample_channel(x, y, 0)); + assert!((a - b).abs() < 1e-3, "90cw, {depth}-bit, grouped {grouped}: ({x},{y}) {a} vs {b}"); + } + } + } + } +} + #[test] fn flattened_mode_pixels_match_the_allocating_conversion_at_every_channel_count() { let px = [[0.0, 0.25, 0.75, 0.0], [0.9, 0.3, 0.2, 0.2], [0.1, 0.7, 0.4, 0.7], [1.0; 4]]; From 7e8386c94c4ae8f1b319d5864c16102180d91404 Mon Sep 17 00:00:00 2001 From: DuBearte <130190089+DuBearte@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:17:34 -0400 Subject: [PATCH 04/35] fix(cms): ignore tags inside .look XML comments (#9109) (#9210) A comment holding / text was read as the LUT, so a commented inverse .look rendered as identity. Drop comments before finding tags. Co-authored-by: Claude Opus 5.5 --- crates/cms/src/lutfile.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/cms/src/lutfile.rs b/crates/cms/src/lutfile.rs index dbe6281d8f..11e3fb24ca 100644 --- a/crates/cms/src/lutfile.rs +++ b/crates/cms/src/lutfile.rs @@ -213,6 +213,15 @@ pub fn parse_3dl(text: &str) -> Result { /// SpeedGrade `.look`: `` and a hex `` string of little-endian float32 RGB triplets /// (red fastest). pub fn parse_look(text: &str) -> Result { + // Comments may hold tag-like text, so drop them before looking for tags (#9109). + let mut clean = String::with_capacity(text.len()); + let mut rest = text; + while let Some(i) = rest.find("").map_or("", |e| &rest[i + 4 + e + 3..]); + } + clean.push_str(rest); + let text = clean.as_str(); let tag = |name: &str| -> Option { let open = format!("<{name}>"); let start = text.find(&open)? + open.len(); @@ -463,6 +472,18 @@ DOMAIN_MAX 0.5 1 1 assert_eq!(parse("a.look", xml.as_bytes()).unwrap().data, id.data); } + #[test] + fn look_ignores_tags_inside_xml_comments() { + let hex = |l: &LutFile| -> String { l.data.iter().flat_map(|v| v.to_le_bytes()).map(|b| format!("{b:02X}")).collect() }; + let inverse = LutFile::from_fn("", 2, |[r, g, b]| [1.0 - r, 1.0 - g, 1.0 - b]); + let xml = format!( + "\"2\"\"{}\"