Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4ff1db3
feat(STAC): Details reads the item's own document: Formatted and JSON…
ianhorn Nov 27, 2026
267bc42
Merge branch 'main' into stac-item-json
ianhorn Nov 27, 2026
6dbc413
Merge branch 'main' into stac-item-json
ianhorn Nov 27, 2026
8c612b9
fix(STAC): the inspector's asset links come from the fetched document…
ianhorn Nov 27, 2026
a1a72fb
fix(STAC): the inspector's Download and Add to map use the address it…
ianhorn Nov 27, 2026
bc42c36
test(STAC): an inspector row acts on the document's own address, rela…
ianhorn Nov 27, 2026
0ffd550
Apply suggestion from @github-actions[bot]
ianhorn Nov 28, 2026
c3f7398
Apply suggestion from @github-actions[bot]
ianhorn Nov 28, 2026
50548b6
Merge branch 'main' into stac-item-json
ianhorn Nov 28, 2026
060daac
fix(STAC): the inspector reads an item's document within 16 MB, off t…
ianhorn Nov 28, 2026
b290c60
fix(STAC): the item's own document is read under the item's reach, an…
ianhorn Nov 28, 2026
de0db17
Apply suggestion from @github-actions[bot]
ianhorn Nov 28, 2026
8db17fe
Apply suggestion from @github-actions[bot]
ianhorn Nov 28, 2026
b378cd2
Merge branch 'main' into stac-item-json
ianhorn Nov 28, 2026
1f59ae7
Merge branch 'main' into stac-item-json
ianhorn Nov 28, 2026
18a9820
Merge branch 'main' into stac-item-json
ianhorn Nov 28, 2026
67122cb
Apply suggestion from @github-actions[bot]
ianhorn Nov 28, 2026
29de48d
Merge branch 'main' into stac-item-json
ianhorn Nov 28, 2026
b7a33fd
Apply suggestion from @github-actions[bot]
ianhorn Nov 28, 2026
40a9c30
Merge branch 'main' into stac-item-json
ianhorn Nov 28, 2026
0dab906
fix(STAC): an item's document is read within 4 MB, one helper cuts th…
ianhorn Nov 28, 2026
97cf3ac
Apply suggestion from @github-actions[bot]
ianhorn Nov 28, 2026
a6e0049
Apply suggestion from @github-actions[bot]
ianhorn Nov 28, 2026
9849363
Merge branch 'main' into stac-item-json
ianhorn Nov 28, 2026
bab9cad
fix(STAC): the laid-out document is bounded, a scheme-bearing asset a…
ianhorn Nov 28, 2026
edbb76a
Merge branch 'main' into stac-item-json
ianhorn Nov 28, 2026
3e28637
fix(STAC): long asset addresses resolve, asset keys are cut, and roun…
ianhorn Nov 28, 2026
e568c28
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
6da3c1c
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
4bb963c
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
ec2258e
Apply suggestion from @github-actions[bot]
ianhorn Nov 29, 2026
02b13ec
fix(STAC): the number scan reads whole tokens, a scheme is kept only …
ianhorn Nov 29, 2026
7643654
fix(STAC): a number with more than 15 digits is named as rounded, the…
ianhorn Nov 29, 2026
2765f19
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
9704b2e
fix(STAC): a document's address is absolute only by its leading schem…
ianhorn Nov 29, 2026
5475351
fix(STAC): a document's item must agree on its collection, an address…
ianhorn Nov 29, 2026
1a1098f
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
5f2a8a9
fix(STAC): an asset's layer name cuts its key, and a document address…
ianhorn Nov 29, 2026
2e84489
Merge branch 'stac-item-json' of https://github.com/ianhorn/RustGIS i…
ianhorn Nov 29, 2026
3bf90cf
fix(STAC): the merged address resolver takes its limit and a document…
ianhorn Nov 29, 2026
c4c7905
fix(STAC): signing an asset keeps a search under way, the fallback JS…
ianhorn Nov 29, 2026
3b3c79d
Apply batched suggestions from code review
ianhorn Nov 29, 2026
2603294
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
ccae927
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
67c3f2e
fix(STAC): a document nested too deeply says so, an asset row with no…
ianhorn Nov 29, 2026
225366b
fix(STAC): signing an asset also waits while a search is being prepared
ianhorn Nov 29, 2026
f9e5e4c
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
714397a
Apply suggestion from @github-actions[bot]
ianhorn Nov 29, 2026
8354fb4
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
466fc2d
fix(STAC): an item's own address is kept up to 64 KB so a long one is…
ianhorn Nov 29, 2026
c81270f
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
2c0a1da
Apply suggestion from @github-actions[bot]
ianhorn Nov 29, 2026
b659f4a
fix(STAC): an item's long own address is not kept per item and the pa…
ianhorn Nov 29, 2026
78de3f5
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
d03365e
Merge branch 'main' into stac-item-json
ianhorn Nov 29, 2026
6d1a7b1
fix(STAC): an own address over any limit is said to be too long, and …
ianhorn Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 93 additions & 18 deletions crates/tiles/src/stac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const MAX_COLLECTIONS: usize = 2000;
/// The most assets read from an item.
const MAX_ASSETS: usize = 100;
/// The longest text kept (titles, ids, addresses).
const MAX_TEXT: usize = 2000;
pub const MAX_TEXT: usize = 2000;
/// The most coordinates a footprint keeps.
const MAX_FOOTPRINT: usize = 20_000;
/// The most properties kept with an item.
Expand Down Expand Up @@ -273,6 +273,8 @@ pub struct Item {
pub assets: Vec<Asset>,
/// Its own address (its `self` link), which relative asset addresses are resolved against.
pub url: Option<String>,
/// It has a `self` link, but one longer than [`MAX_TEXT`], which is not kept (so `url` is `None`).
pub url_too_long: bool,
/// The address it was fetched from, which its asset addresses are judged by (never its own
/// `self` link, which it could point anywhere); `None` for an item given whole, whose assets
/// may then only be public web addresses.
Expand Down Expand Up @@ -695,14 +697,24 @@ pub fn item_from_json(v: &Value, from: Option<&str>) -> Option<Item> {
item(v, from)
}

/// A link's address by its relation, resolved against `from`.
fn link(v: &Value, rel: &str, from: &str) -> Option<String> {
/// A link by its relation: its plain GET entry, if it has one.
fn link_entry<'a>(v: &'a Value, rel: &str) -> Option<&'a Value> {
let l = v.get("links")?.as_array()?.iter().take(100).find(|l| l.get("rel").and_then(Value::as_str) == Some(rel))?;
// A POST link needs its body: only a plain GET is followed.
if l.get("method").and_then(Value::as_str).is_some_and(|m| !m.eq_ignore_ascii_case("GET")) {
return None;
}
resolve(from, l.get("href")?.as_str()?)
Some(l)
}

/// A link's address by its relation, resolved against `from`.
fn link(v: &Value, rel: &str, from: &str) -> Option<String> {
resolve(from, link_entry(v, rel)?.get("href")?.as_str()?)
}

/// Whether a link has an address longer than the text limit, which [`link`] refuses.
fn link_too_long(v: &Value, rel: &str) -> bool {
link_entry(v, rel).and_then(|l| l.get("href")?.as_str()).is_some_and(|h| h.trim().len() > MAX_TEXT)
}

fn item(f: &Value, from: Option<&str>) -> Option<Item> {
Expand All @@ -722,6 +734,8 @@ pub(crate) fn item_with_reach(f: &Value, from: Option<&str>, reach: Option<crate
Some(from) => link(f, "self", from),
None => link(f, "self", "").filter(|u| is_web(u)),
};
// Kept on every item of a search only up to the text limit; a longer one is said to be so.
let url_too_long = url.is_none() && link_too_long(f, "self");
let base = url.clone().or_else(|| from.map(str::to_string));
let props = f.get("properties");
let bbox = f.get("bbox").and_then(Value::as_array).and_then(|b| {
Expand Down Expand Up @@ -826,6 +840,7 @@ pub(crate) fn item_with_reach(f: &Value, from: Option<&str>, reach: Option<crate
cloud,
assets,
url,
url_too_long,
origin: from.map(str::to_string),
origin_reach,
properties,
Expand Down Expand Up @@ -898,10 +913,23 @@ fn footprint_size(g: &Value) -> usize {
/// An address relative to another, as a browser would resolve it (`s3://` and others are kept
/// as they are, so they can be refused by name).
pub fn resolve(base: &str, href: &str) -> Option<String> {
resolve_up_to(base, href, MAX_TEXT, false)
}

/// [`resolve`] for an address from an item's own document, which is not cut to the parsed item's
/// text limit: up to [`MAX_DOCUMENT_HREF`] bytes (64 KB), so a long relative address still resolves.
pub fn resolve_document_href(base: &str, href: &str) -> Option<String> {
resolve_up_to(base, href, MAX_DOCUMENT_HREF, true)
Comment thread
ianhorn marked this conversation as resolved.
Resolved
}

/// The most bytes of an address taken from an item's own document.
pub const MAX_DOCUMENT_HREF: usize = 64 << 10;

fn resolve_up_to(base: &str, href: &str, limit: usize, schemes: bool) -> Option<String> {
// A login binding rides along only to an address on the base's own origin (`inherit`).
let plain_base = rustgis_data::login_address::parse(base).ok()?.map_or(base, |b| b.url);
rustgis_data::login_address::parse(href).ok()?;
let resolved = resolve_plain(plain_base, crate::logins::inner(href))?;
let resolved = resolve_plain(plain_base, crate::logins::inner(href), limit, schemes)?;
Comment thread
ianhorn marked this conversation as resolved.
Resolved
Some(crate::logins::inherit(base, &resolved))
}

Expand All @@ -912,12 +940,24 @@ fn has_scheme(s: &str) -> bool {
bytes.next().is_some_and(|b| b.is_ascii_alphabetic()) && bytes.all(|b| b.is_ascii_alphanumeric() || matches!(b, b'+' | b'-' | b'.'))
}

fn resolve_plain(base: &str, href: &str) -> Option<String> {
/// Whether `href` begins with a URI scheme even without `//` (`data:`, `mailto:`): a letter, then
/// letters, digits, `+`, `-` or `.`, then a colon. A single letter (`c:/a.tif`) is a drive, not a
/// scheme, which matches what `check_asset_scheme` names.
fn has_uri_scheme(href: &str) -> bool {
href.split_once(':').is_some_and(|(s, rest)| {
s.starts_with(|c: char| c.is_ascii_alphabetic())
&& s.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '+' | '-' | '.'))
&& (s.len() > 1 || !rest.starts_with(['/', '\\']))
})
}
Comment thread
ianhorn marked this conversation as resolved.
Resolved

fn resolve_plain(base: &str, href: &str, limit: usize, schemes: bool) -> Option<String> {
let href = href.trim();
if href.is_empty() || href.len() > MAX_TEXT || href.chars().any(char::is_control) {
if href.is_empty() || href.len() > limit || href.chars().any(char::is_control) {
return None;
}
if has_scheme(href) {
// A document's address with a scheme of its own (`data:`, `mailto:`) is kept as written too.
if has_scheme(href) || (schemes && has_uri_scheme(href)) {
return Some(href.to_string());
}
let (scheme, rest) = base.split_once("://")?;
Expand Down Expand Up @@ -1038,19 +1078,47 @@ impl Item {
/// may point to, not one that needs signing or a cloud store's own protocol.
pub fn asset_href(&self, key: Option<&str>) -> Result<(String, String), String> {
let a = self.pick(key)?;
let lower = crate::logins::inner(&a.href).to_ascii_lowercase();
if !(lower.starts_with("https://") || lower.starts_with("http://") || crate::s3::is_s3(&lower)) {
let scheme = lower.split("://").next().unwrap_or("");
return Err(format!(
"{}: asset '{}' is at {} (a {scheme}:// address); RustGIS adds assets by their web or s3:// address",
self.id, a.key, a.href
));
}
self.check_asset_href(&a.key, &a.href)?;
Ok((a.key.clone(), a.href.clone()))
}

/// Checks an address given for asset `key` as [`Item::asset_href`] checks the item's own: a
/// web or s3:// address that the item's origin and reach allow.
pub fn check_asset_href(&self, key: &str, href: &str) -> Result<(), String> {
self.check_asset_scheme(key, href)?;
// Judged by where the item came from; an item given whole may only point at public
// addresses (as a document on the web may). A Planetary Computer asset is signed by the
// caller ([`needs_signing`]).
self.check_href(&a.href)?;
Ok((a.key.clone(), a.href.clone()))
self.check_href(href)
}

/// The scheme half of [`Item::check_asset_href`], for an address judged against another
/// document's origin: a web or s3:// address, else an error naming what it is.
pub fn check_asset_scheme(&self, key: &str, href: &str) -> Result<(), String> {
let lower = crate::logins::inner(href).to_ascii_lowercase();
if lower.starts_with("https://") || lower.starts_with("http://") || crate::s3::is_s3(&lower) {
return Ok(());
}
// The scheme is the letters before the first colon (`data:` and `mailto:` have no `//`).
let scheme = lower
Comment thread
ianhorn marked this conversation as resolved.
Resolved
.split_once(':')
.filter(|(s, rest)| s.len() > 1 || !rest.starts_with(['/', '\\']))
.map(|(s, _)| s)
.filter(|s| s.starts_with(|c: char| c.is_ascii_alphabetic()))
.filter(|s| s.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'+' | b'-' | b'.')));
let slashes = lower.split_once(':').is_some_and(|(_, rest)| rest.starts_with("//"));
let what = match (scheme, slashes) {
(Some(scheme), true) => format!("a {scheme}:// address"),
(Some(scheme), false) => format!("a {scheme}: address"),
(None, _) => "a relative address that couldn't be made absolute".to_string(),
};
let cut = href.chars().count() > 200;
let shown: String = href.chars().take(200).chain(cut.then_some('…')).collect();
Err(format!(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small points on this message, grouped:

  1. href is printed as written. It can be a login-wrapped address (logins::inherit wraps a same-origin link when the document's base has a binding), so the text may show the wrapper rather than the address. start_json already passes its address through address_in_message for the same kind of message. Using it here would keep the two consistent.
  2. The scheme is now read in three places: has_scheme (about line 934), has_uri_scheme (about line 943) and this function. All three must agree on what counts as a scheme (the one-letter drive rule and the allowed characters). One helper that returns the scheme would keep them in step.

Both are wording and consistency points, not wrong results.

Category: quality

"{}: asset '{}' is at {shown} ({what}); RustGIS adds assets by their web or s3:// address",
self.id,
key.chars().take(200).collect::<String>()
))
}
}

Expand Down Expand Up @@ -1658,6 +1726,13 @@ mod tests {
let i = item_from_json(&f("item.json", "https://data.example.org/x.tif"), None).unwrap();
assert!(i.asset_href(None).is_ok());
assert!(item_from_json(&f("item.json", "x.tif"), None).unwrap().assets.is_empty());
// A self address past the 2,000-byte text limit is not kept, and the item says so.
for n in [3000, 100_000] {
let long = format!("https://stac.example.org/items/{}", "a".repeat(n));
let i = item_from_json(&f(&long, "https://data.example.org/x.tif"), None).unwrap();
assert!(i.url.is_none() && i.url_too_long, "{n}");
}
assert!(!item_from_json(&f("item.json", "https://data.example.org/x.tif"), None).unwrap().url_too_long);
// Dates: each side a date, a date and time, or open.
for good in ["2024-06-01", "2024-06-01/2024-06-30", "2024-06-01/..", "../2024-06-30", "2024-06-01T10:00:00Z/.."] {
assert!(datetime(good).is_ok(), "{good}");
Expand Down
Loading
Loading