From ad68f8a19fbb20cc3cdcf025fb2e9e03f90d4f8c Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 25 Nov 2026 17:33:45 -0500 Subject: [PATCH 1/2] fix(data): a Shapefile export no longer stops the web app A Shapefile's .dbf header holds the day it was written, which the dbase crate reads from time::OffsetDateTime::now_utc(). Without time's wasm-bindgen feature that clock is std's, which panics on wasm32-unknown-unknown ("time not implemented on this platform"), so every Shapefile export in the browser killed the app and left the tab frozen with no message, whatever the layer's size or fields. Turn on time's wasm-bindgen feature for wasm32 in rustgis-data, so the clock is JavaScript's Date. A test checks that writing a .dbf stamps the day and that the manifest keeps the feature on for wasm32. Reported in opengeos/GeoLibre#3648. --- Cargo.lock | 2 ++ crates/data/Cargo.toml | 6 ++++++ crates/data/src/io.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 80bd63ca8a..9bfcb88ccd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5263,6 +5263,7 @@ dependencies = [ "thiserror 2.0.21", "tiberius", "tiff", + "time", "tokio", "tokio-postgres-rustls", "tokio-util", @@ -6468,6 +6469,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" dependencies = [ "deranged", + "js-sys", "num-conv", "powerfmt", "serde_core", diff --git a/crates/data/Cargo.toml b/crates/data/Cargo.toml index d5e3d7bac6..cb7789aeaf 100644 --- a/crates/data/Cargo.toml +++ b/crates/data/Cargo.toml @@ -50,6 +50,12 @@ ruzstd = { workspace = true } lerc-reader = { workspace = true } lerc-core = { workspace = true } +# A Shapefile's `.dbf` header holds the day it was written, which `dbase` reads from `time`'s +# clock. Without this feature that clock is std's, which panics in the browser, so a Shapefile +# export stopped the web app (opengeos/GeoLibre#3648); with it, the clock is JavaScript's. +[target.'cfg(target_arch = "wasm32")'.dependencies] +time = { version = "0.3", default-features = false, features = ["wasm-bindgen"] } + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] rusqlite = { workspace = true } postgres = { workspace = true } diff --git a/crates/data/src/io.rs b/crates/data/src/io.rs index e5dd5d686d..cbd6e3b23d 100644 --- a/crates/data/src/io.rs +++ b/crates/data/src/io.rs @@ -6042,6 +6042,34 @@ mod tests { use super::*; use std::io::Write; + /// A Shapefile's `.dbf` header holds the day it was written, which `dbase` takes from `time`'s + /// clock: std's unless `time`'s `wasm-bindgen` feature is on, and std's clock panics on + /// wasm32-unknown-unknown, so every Shapefile export stopped the web app with no message + /// (opengeos/GeoLibre#3648). The browser build can't run here, so this checks both halves: + /// that writing a `.dbf` does read the clock, and that this crate turns the feature on for + /// wasm32. + #[test] + fn a_shapefile_written_in_the_browser_reads_the_clock_through_javascript() { + let mut ds = Dataset::new("pts", GeometryType::Point, vec![Field::new("n", FieldType::Integer)]); + ds.push(Some(Geometry::Point(Coord::new(1.0, 2.0))), vec![Value::Int(1)]); + let (parts, _) = shapefile_parts_in(&ds, Crs::LonLat).unwrap(); + let dbf = &parts.iter().find(|(e, _)| *e == "dbf").unwrap().1; + // Bytes 1 to 3: the year since 1900, the month and the day it was written. + let year = 1900 + u32::from(dbf[1]); + assert!((2024..2156).contains(&year), "the .dbf header holds the day it was written: {year}"); + assert!((1..=12).contains(&dbf[2]) && (1..=31).contains(&dbf[3]), "{:?}", &dbf[1..4]); + + let manifest = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml")); + let wasm = manifest + .split("\n[") + .find(|section| section.starts_with("target.'cfg(target_arch = \"wasm32\")'.dependencies]")) + .expect("crates/data/Cargo.toml has a [target.'cfg(target_arch = \"wasm32\")'.dependencies] section"); + assert!( + wasm.lines().any(|l| l.starts_with("time ") && l.contains("\"wasm-bindgen\"")), + "time's wasm-bindgen feature is on for wasm32, or a Shapefile export panics in the browser:\n{wasm}" + ); + } + /// A write to a name nothing holds reserves it first: a second write to it is refused before /// anything is written, and dropping the write removes the reservation and the folder made for /// it; once installed, both stay (#2865). From 887138b3daac2035bd4114d85c9f03717dd09546 Mon Sep 17 00:00:00 2001 From: giswqs Date: Wed, 25 Nov 2026 18:14:40 -0500 Subject: [PATCH 2/2] Address review feedback - Claude: rename the test to what it checks on the host (a_shapefile_dbf_is_stamped_with_the_day_it_was_written), keep the browser claim in its doc comment, normalise CRLF and say why the manifest is matched as text. - CodeRabbit: compare the .dbf header with the UTC date taken just before and after the write, so a fixed date can't pass. --- crates/data/src/io.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/data/src/io.rs b/crates/data/src/io.rs index cbd6e3b23d..adb0983d7a 100644 --- a/crates/data/src/io.rs +++ b/crates/data/src/io.rs @@ -6045,21 +6045,30 @@ mod tests { /// A Shapefile's `.dbf` header holds the day it was written, which `dbase` takes from `time`'s /// clock: std's unless `time`'s `wasm-bindgen` feature is on, and std's clock panics on /// wasm32-unknown-unknown, so every Shapefile export stopped the web app with no message - /// (opengeos/GeoLibre#3648). The browser build can't run here, so this checks both halves: - /// that writing a `.dbf` does read the clock, and that this crate turns the feature on for - /// wasm32. + /// (opengeos/GeoLibre#3648). The browser build can't run here, so this checks both halves on + /// the host: that writing a `.dbf` stamps today's date (it reads the clock), and that this + /// crate turns the feature on for wasm32. #[test] - fn a_shapefile_written_in_the_browser_reads_the_clock_through_javascript() { + fn a_shapefile_dbf_is_stamped_with_the_day_it_was_written() { + let today = || { + let secs = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs(); + let (y, m, d) = crate::date::civil_from_days(i64::try_from(secs / 86_400).unwrap()); + (y - 1900, m, d) + }; let mut ds = Dataset::new("pts", GeometryType::Point, vec![Field::new("n", FieldType::Integer)]); ds.push(Some(Geometry::Point(Coord::new(1.0, 2.0))), vec![Value::Int(1)]); + let before = today(); let (parts, _) = shapefile_parts_in(&ds, Crs::LonLat).unwrap(); + let after = today(); let dbf = &parts.iter().find(|(e, _)| *e == "dbf").unwrap().1; - // Bytes 1 to 3: the year since 1900, the month and the day it was written. - let year = 1900 + u32::from(dbf[1]); - assert!((2024..2156).contains(&year), "the .dbf header holds the day it was written: {year}"); - assert!((1..=12).contains(&dbf[2]) && (1..=31).contains(&dbf[3]), "{:?}", &dbf[1..4]); - - let manifest = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml")); + // Bytes 1 to 3: the year since 1900, the month and the day it was written (UTC), either + // side of a midnight passed during the write. + let stamped = (i64::from(dbf[1]), i64::from(dbf[2]), i64::from(dbf[3])); + assert!(stamped == before || stamped == after, "{stamped:?}, written between {before:?} and {after:?}"); + + // A plain text match, so the test needs no TOML parser: it is loud, not silent, if the + // section is ever written another way (a `[target.….dependencies.time]` table). + let manifest = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml")).replace("\r\n", "\n"); let wasm = manifest .split("\n[") .find(|section| section.starts_with("target.'cfg(target_arch = \"wasm32\")'.dependencies]"))