From 159523b5558ca61eb6426ec372523461850a07eb Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Fri, 6 Nov 2026 23:46:59 -0300 Subject: [PATCH 1/3] fix(engine): keep a cloud-optimised GeoTIFF's look in a saved project MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A plain web address lost everything after `#` when saved, so a COG lost its `#range=…` and `#bands=…`, a data cube lost its fixed range on every date, and saving counted each address as a removed key. Only a look stays: any other fragment still goes, as OAuth and SAS-style links carry tokens there. `dequantize` in a look now takes only `aef` or `none`, since a look is saved as written and must not hold free text. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/project.rs | 7 +++- crates/engine/src/tests.rs | 72 ++++++++++++++++++++++++++++++++++++ crates/tiles/src/cog.rs | 8 +++- docs/user-guide/workspace.md | 3 +- 4 files changed, 86 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index dae43f5eed..a816e117cb 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -65,7 +65,8 @@ pub const MAX_BYTES: u64 = 512 << 20; /// The address a saved file keeps. Only web addresses can contain layer credentials. A tile /// template (`pmtiles:…@archive`, `cog:…@archive`) is judged by its archive, and an address read /// through a saved S3 connection by the address it wraps, the wrapper rebuilt around it (its -/// binding and endpoint are provenance, not secrets); a COG's look after either is kept. +/// binding and endpoint are provenance, not secrets). A COG's look is kept, on any of these and on +/// a plain address; any other fragment isn't, as OAuth and SAS-style links carry tokens there. fn saved_address(address: &str) -> Option { if let Some(public) = without_login_binding(address) { return Some(saved_address(&public).unwrap_or(public)); @@ -87,7 +88,8 @@ fn saved_address(address: &str) -> Option { if !["http", "https", "s3"].iter().any(|s| protocol.eq_ignore_ascii_case(s)) { return None; } - let (scheme, mut rest) = address.split_once("://")?; + let (file, look) = split_look(address); + let (scheme, mut rest) = file.split_once("://")?; let end = rest.find(['/', '?', '#']).unwrap_or(rest.len()); if let Some(at) = rest.get(..end).and_then(|authority| authority.rfind('@')) { rest = rest.get(at + 1..)?; @@ -95,6 +97,7 @@ fn saved_address(address: &str) -> Option { let rest = rest.split('#').next().unwrap_or(rest); let mut out = format!("{scheme}://{rest}"); rustgis_data::source::credentials::redact_query(&mut out); + out.push_str(look); (out != address).then_some(out) } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index fde19769af..da38100c14 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -18070,6 +18070,78 @@ fn layer_address_redaction_preserves_templates_and_local_paths() { assert_eq!(anonymous, format!("{prefix}https://bucket.example/a")); } +/// A COG's look isn't a key: it stays in a saved address. The address's keys still go, and so does +/// any other fragment (OAuth and SAS links carry tokens there), however much it resembles a look. +#[test] +fn layer_address_redaction_keeps_a_cogs_look() { + let prefix = crate::render::rustgis_tiles::s3::ANONYMOUS; + let bound = rustgis_data::login_address::bind("0123456789abcdef", "https://h.example", "https://h.example/a.tif#range=0,1000").unwrap(); + let cases = [ + // Nothing to take out: no change at all. + ("https://h.example/a.tif#range=0,1000".to_string(), "https://h.example/a.tif#range=0,1000".to_string()), + ( + "s3://bucket/a.tif#bands=2,3,4&range=-0.5,0.5&dequantize=aef".into(), + "s3://bucket/a.tif#bands=2,3,4&range=-0.5,0.5&dequantize=aef".into(), + ), + (format!("{prefix}https://h.example/a.tif#bands=1"), format!("{prefix}https://h.example/a.tif#bands=1")), + // Its keys go, its look stays. + ("https://u:p@h.example/a.tif?token=s3cret&v=1#range=0,1000".into(), "https://h.example/a.tif?v=1#range=0,1000".into()), + ("https://u:p@h.example#range=0,1000".into(), "https://h.example#range=0,1000".into()), + (format!("{prefix}https://h.example/a.tif?token=s3cret#bands=1"), format!("{prefix}https://h.example/a.tif#bands=1")), + (bound, "https://h.example/a.tif#range=0,1000".into()), + // Not a look: it goes as before. + ("https://h.example/a.tif#access_token=s3cret".into(), "https://h.example/a.tif".into()), + ("https://h.example/a.tif#range=0,1000&token=s3cret".into(), "https://h.example/a.tif".into()), + ("https://h.example/a.tif#dequantize=s3cret".into(), "https://h.example/a.tif".into()), + ("https://h.example/a.tif#range=0,1000?token=s3cret".into(), "https://h.example/a.tif".into()), + ("https://h.example/a.tif#dequantize=aef?token=s3cret".into(), "https://h.example/a.tif".into()), + // A look after another fragment: only the look stays. + ("https://h.example/a.tif#sig=s3cret#range=0,1000".into(), "https://h.example/a.tif#range=0,1000".into()), + ]; + let mut addresses: Vec = cases.iter().map(|(a, _)| a.clone()).collect(); + crate::project::strip_addresses(addresses.iter_mut().collect()); + for (address, (given, expected)) in addresses.iter().zip(&cases) { + assert_eq!(address, expected, "from {given}"); + } +} + +/// A data cube saved with one range for all its dates opens with that range, and saving it says +/// nothing about keys. A key among its addresses goes and is counted, and only that one. +#[test] +fn saved_cubes_keep_their_look() { + let mut s = Session::new(Project::default()); + let mut cube = rustgis_map::TileLayer::new("Cube", rustgis_map::TileKind::Cog, "https://h.example/2021.tif#range=0,1000"); + cube.time_urls = vec![(1.0, "https://h.example/2020.tif#range=0,1000".into()), (2.0, "https://h.example/2021.tif#range=0,1000".into())]; + let expected = (cube.url.clone(), cube.time_urls.clone()); + s.map_mut().tiles.push(cube); + let dir = std::env::temp_dir().join(format!("rustgis-cube-look-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let path = dir.join("cube.rgis"); + + // Clean: nothing was taken out, so nothing is said. + let saved = s.run("project.saveAs", &json!({"path": path})).unwrap(); + assert_eq!(saved["stripped"], 0, "{saved}"); + assert!(!s.notices.iter().any(|n| n.text.contains("saved without their keys"))); + let mut t = Session::new(Project::default()); + t.run("project.open", &json!({"path": path})).unwrap(); + let opened = &t.map().tiles[0]; + assert_eq!((opened.url.clone(), opened.time_urls.clone()), expected); + + // Lossy: one date's token goes and is counted; its look stays; the open project keeps it all. + let with_key = "https://h.example/2020.tif?token=s3cret#range=0,1000"; + s.map_mut().tiles[0].time_urls[0].1 = with_key.into(); + let saved = s.run("project.saveAs", &json!({"path": path})).unwrap(); + assert_eq!(saved["stripped"], 1, "{saved}"); + assert!(s.notices.iter().any(|n| n.text.starts_with("1 layer address(es) were saved without their keys"))); + assert_eq!(s.map().tiles[0].time_urls[0].1, with_key); + let text = std::fs::read_to_string(&path).unwrap(); + assert!(!text.contains("s3cret") && text.contains("https://h.example/2020.tif#range=0,1000"), "{text}"); + // Opened again before RustGIS closes, it has its token back, with its look. + t.run("project.open", &json!({"path": path})).unwrap(); + assert_eq!(t.map().tiles[0].time_urls[0].1, with_key); + let _ = std::fs::remove_dir_all(dir); +} + #[test] fn saved_layer_files_keep_no_address_secrets() { let mut s = world(); diff --git a/crates/tiles/src/cog.rs b/crates/tiles/src/cog.rs index 8e98a73785..4756cf1181 100644 --- a/crates/tiles/src/cog.rs +++ b/crates/tiles/src/cog.rs @@ -107,7 +107,8 @@ impl Look { } look.range = Some((lo, hi)); } - "dequantize" => look.aef = v == "aef", + // Only these words: a saved project keeps a look as written, so it holds no free text. + "dequantize" if v == "aef" || v == "none" => look.aef = v == "aef", _ => return None, } } @@ -1398,6 +1399,11 @@ mod tests { assert_eq!(split(&shown), (u, look)); // Another look replaces it; the file's own adds nothing. assert_eq!(with_look(&shown, &Look::default()), u); + // Only what a look can say makes one: a saved project keeps looks and no other fragment. + assert_eq!(split("https://x.org/a.tiff#dequantize=none"), (u, Look::default())); + for other in ["https://x.org/a.tiff#dequantize=s3cret", "https://x.org/a.tiff#range=0,1&dequantize=aef?token=s3cret"] { + assert_eq!(split(other), (other, Look::default())); + } // A template keeps the look, so each look's map tiles are their own. let (_, _, _, archive) = parse_url(&template(&shown).replace("{z}/{x}/{y}", "1/0/0")).unwrap(); assert_eq!(split(&archive).0, u); diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index 5cf4a33dcb..d2e8eb67ba 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -34,7 +34,8 @@ back the next time it starts; with autosave off, they are lost, so save before y Saved layer addresses omit passwords, access keys, tokens and signatures. The open session keeps them, but after restarting RustGIS a protected source may need you to sign in to its -connection again or add it again with credentials. +connection again or add it again with credentials. A cloud-optimised GeoTIFF's look in its address +(`#bands=…`, `#range=…`, a data cube's fixed range too) is saved; any other `#` part isn't. ### Autosave and recovery From fe22ec774dca6d5f41af9c5fa3a2697bdce04742 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Sat, 7 Nov 2026 00:05:25 -0300 Subject: [PATCH 2/3] fix(engine): decide what a saved look may hold when saving, not when reading Tightening `Look::parse` also changed how an address is read: a hand-typed `#range=0,1&dequantize=other` lost its range, unsaid. Reading stays as it was; `split_look` now refuses to keep a look whose `dequantize` is another word. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/project.rs | 8 ++++++-- crates/engine/src/tests.rs | 10 ++++++++++ crates/tiles/src/cog.rs | 8 +------- docs/user-guide/workspace.md | 3 ++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index a816e117cb..48c5feac4d 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -101,10 +101,14 @@ fn saved_address(address: &str) -> Option { (out != address).then_some(out) } -/// A COG address without its look (`…#bands=…`), and the look as written. +/// A COG address without its look (`…#bands=…`), and the look as written. A reader takes any word +/// for `dequantize`, but a saved look holds only numbers and that key's own words: with another +/// word it stays in the address, and goes as any other fragment does. fn split_look(address: &str) -> (&str, &str) { let file = crate::render::rustgis_tiles::cog::split(address).0; - (file, address.get(file.len()..).unwrap_or("")) + let look = address.get(file.len()..).unwrap_or(""); + let own_words = look.split(['#', '&']).filter_map(|kv| kv.strip_prefix("dequantize=")).all(|word| matches!(word, "aef" | "none")); + if own_words { (file, look) } else { (address, "") } } /// Strips layer credentials, keeping originals in the visitor's order for the caller to restore. diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index da38100c14..e49055b70d 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -18095,6 +18095,16 @@ fn layer_address_redaction_keeps_a_cogs_look() { ("https://h.example/a.tif#dequantize=s3cret".into(), "https://h.example/a.tif".into()), ("https://h.example/a.tif#range=0,1000?token=s3cret".into(), "https://h.example/a.tif".into()), ("https://h.example/a.tif#dequantize=aef?token=s3cret".into(), "https://h.example/a.tif".into()), + // A word `dequantize` doesn't have: a reader takes it as a look, a saved file doesn't. + ("https://h.example/a.tif#range=0,1000&dequantize=s3cret".into(), "https://h.example/a.tif".into()), + ("cog:{z}/{x}/{y}@https://h.example/a.tif#dequantize=s3cret".into(), "cog:{z}/{x}/{y}@https://h.example/a.tif".into()), + ( + rustgis_data::s3_address::bind("", "s3.example.org", "https://h.example/a.tif#dequantize=s3cret").unwrap(), + rustgis_data::s3_address::bind("", "s3.example.org", "https://h.example/a.tif").unwrap(), + ), + // Its own words stay. + ("https://h.example/a.tif#range=0,1000&dequantize=none".into(), "https://h.example/a.tif#range=0,1000&dequantize=none".into()), + ("cog:{z}/{x}/{y}@https://h.example/a.tif#dequantize=aef".into(), "cog:{z}/{x}/{y}@https://h.example/a.tif#dequantize=aef".into()), // A look after another fragment: only the look stays. ("https://h.example/a.tif#sig=s3cret#range=0,1000".into(), "https://h.example/a.tif#range=0,1000".into()), ]; diff --git a/crates/tiles/src/cog.rs b/crates/tiles/src/cog.rs index 4756cf1181..8e98a73785 100644 --- a/crates/tiles/src/cog.rs +++ b/crates/tiles/src/cog.rs @@ -107,8 +107,7 @@ impl Look { } look.range = Some((lo, hi)); } - // Only these words: a saved project keeps a look as written, so it holds no free text. - "dequantize" if v == "aef" || v == "none" => look.aef = v == "aef", + "dequantize" => look.aef = v == "aef", _ => return None, } } @@ -1399,11 +1398,6 @@ mod tests { assert_eq!(split(&shown), (u, look)); // Another look replaces it; the file's own adds nothing. assert_eq!(with_look(&shown, &Look::default()), u); - // Only what a look can say makes one: a saved project keeps looks and no other fragment. - assert_eq!(split("https://x.org/a.tiff#dequantize=none"), (u, Look::default())); - for other in ["https://x.org/a.tiff#dequantize=s3cret", "https://x.org/a.tiff#range=0,1&dequantize=aef?token=s3cret"] { - assert_eq!(split(other), (other, Look::default())); - } // A template keeps the look, so each look's map tiles are their own. let (_, _, _, archive) = parse_url(&template(&shown).replace("{z}/{x}/{y}", "1/0/0")).unwrap(); assert_eq!(split(&archive).0, u); diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index d2e8eb67ba..0f101bfc6c 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -35,7 +35,8 @@ back the next time it starts; with autosave off, they are lost, so save before y Saved layer addresses omit passwords, access keys, tokens and signatures. The open session keeps them, but after restarting RustGIS a protected source may need you to sign in to its connection again or add it again with credentials. A cloud-optimised GeoTIFF's look in its address -(`#bands=…`, `#range=…`, a data cube's fixed range too) is saved; any other `#` part isn't. +(`#bands=…`, `#range=…`, `#dequantize=aef`, a data cube's fixed range too) is saved; any other `#` +part isn't. ### Autosave and recovery From 0bc424f28d2f66c44b7706812e417d25abfacdc5 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Sat, 7 Nov 2026 00:22:10 -0300 Subject: [PATCH 3/3] fix(engine): a saved look holds only numbers and its keys' own words After #1339 a look also has `cube`, which takes any word as `dequantize` does. `split_look` now names what may stay, so a key added later isn't saved as written until it is named here. A one-file cube keeps its `#cube=1`, the only thing that keeps it a tile layer when its project opens. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/project.rs | 11 +++++++---- crates/engine/src/tests.rs | 11 +++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index ed4c902354..378461db22 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -102,13 +102,16 @@ fn saved_address(address: &str) -> Option { } /// A COG address without its look (`…#bands=…`), and the look as written. A reader takes any word -/// for `dequantize`, but a saved look holds only numbers and that key's own words: with another -/// word it stays in the address, and goes as any other fragment does. +/// for `dequantize` and `cube`, but a saved look holds only numbers and these keys' own words: any +/// other, or a key not named here, stays in the address and goes as any other fragment does. fn split_look(address: &str) -> (&str, &str) { let file = crate::render::rustgis_tiles::cog::split(address).0; let look = address.get(file.len()..).unwrap_or(""); - let own_words = look.split(['#', '&']).filter_map(|kv| kv.strip_prefix("dequantize=")).all(|word| matches!(word, "aef" | "none")); - if own_words { (file, look) } else { (address, "") } + let plain = look.split(['#', '&']).filter(|kv| !kv.is_empty()).all(|kv| { + // `Look::parse` has checked that `bands` and `range` are numbers. + matches!(kv.split_once('='), Some(("bands" | "range", _) | ("dequantize", "aef" | "none") | ("cube", "0" | "1"))) + }); + if plain { (file, look) } else { (address, "") } } /// Strips layer credentials, keeping originals in the visitor's order for the caller to restore. diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 0cdda93b1e..6d93f0398f 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -19172,6 +19172,8 @@ fn layer_address_redaction_keeps_a_cogs_look() { // Its own words stay. ("https://h.example/a.tif#range=0,1000&dequantize=none".into(), "https://h.example/a.tif#range=0,1000&dequantize=none".into()), ("cog:{z}/{x}/{y}@https://h.example/a.tif#dequantize=aef".into(), "cog:{z}/{x}/{y}@https://h.example/a.tif#dequantize=aef".into()), + ("https://h.example/a.tif#range=0,1000&cube=1".into(), "https://h.example/a.tif#range=0,1000&cube=1".into()), + ("https://h.example/a.tif#cube=s3cret".into(), "https://h.example/a.tif".into()), // A look after another fragment: only the look stays. ("https://h.example/a.tif#sig=s3cret#range=0,1000".into(), "https://h.example/a.tif#range=0,1000".into()), ]; @@ -19216,6 +19218,15 @@ fn saved_cubes_keep_their_look() { // Opened again before RustGIS closes, it has its token back, with its look. t.run("project.open", &json!({"path": path})).unwrap(); assert_eq!(t.map().tiles[0].time_urls[0].1, with_key); + + // A cube of one file: its address is all that keeps it a tile layer when its project opens. + let one_file = "https://h.example/2020.tif#range=0,1000&cube=1"; + let mut one = Session::new(Project::default()); + one.map_mut().tiles.push(rustgis_map::TileLayer::new("One date", rustgis_map::TileKind::Cog, one_file)); + let saved = one.run("project.saveAs", &json!({"path": path})).unwrap(); + assert_eq!(saved["stripped"], 0, "{saved}"); + t.run("project.open", &json!({"path": path})).unwrap(); + assert_eq!(t.map().tiles[0].url, one_file); let _ = std::fs::remove_dir_all(dir); }