PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Print: a scoped IPv6 endpoint escapes its zone id in the request authority
Codexc06a7384a588
diff --git a/crates/ipp/src/lib.rs b/crates/ipp/src/lib.rsindex b5863e910..6fe103249 100644--- a/crates/ipp/src/lib.rs+++ b/crates/ipp/src/lib.rs@@ -175,11 +175,17 @@ impl Endpoint {}/// The endpoint as an HTTP authority: an IPv6 host is bracketed, or its last colon reads as the- /// port separator and the request carries a host CUPS has never heard of.+ /// port separator and the request carries a host CUPS has never heard of. A scoped address keeps+ /// its zone id and writes it escaped as "%25": "%" is not valid inside an authority (RFC 3986+ /// section 3.2.2 reserves it for escaping), and the escaped form is what CUPS, curl and the+ /// ipp:// URIs CUPS writes use for a zone. RFC 9844 (Aug 2025) obsoleted RFC 6874, which had made+ /// that form URI syntax, so this is interop rather than a standard; dropping the zone instead+ /// would name a different host on the wire than the socket was opened to. The socket still gets+ /// the raw address%zone, which is the form a resolver understands.fn host(&self) -> String {match self {Endpoint::Unix(_) => "localhost".into(),- Endpoint::Tcp(host, port) if host.contains(':') => format!("[{host}]:{port}"),+ Endpoint::Tcp(host, port) if host.contains(':') => format!("[{}]:{port}", host.replace('%', "%25")),Endpoint::Tcp(host, port) => format!("{host}:{port}"),}}diff --git a/crates/ipp/src/tests.rs b/crates/ipp/src/tests.rsindex bc08594ad..02623f71d 100644--- a/crates/ipp/src/tests.rs+++ b/crates/ipp/src/tests.rs@@ -158,7 +158,10 @@ fn a_print_job_carries_the_document_and_returns_its_id() {assert_eq!(op, OP_PRINT_JOB);assert_eq!(doc, pdf);let get = |n: &str| attrs.iter().find(|a| a.name == n).cloned().unwrap_or_else(|| panic!("{n}"));- assert_eq!(get("printer-uri").values[0], format!("ipp://{}/printers/Office", ep.host()).as_bytes());+ let uri = String::from_utf8(get("printer-uri").values[0].clone()).unwrap();+ // Spelled out here rather than echoed back from host(), so the printer-uri the server receives is+ // pinned down even when the authority is an IP literal.+ assert!(uri.starts_with("ipp://127.0.0.1:") && uri.ends_with("/printers/Office"), "{uri}");assert_eq!(get("job-name").values[0], b"photo.psd");assert_eq!(get("requesting-user-name").values[0], b"diego");assert_eq!(get("document-format").values[0], b"application/pdf");@@ -267,9 +270,17 @@ fn an_ipv6_endpoint_writes_its_authority_in_brackets() {assert_eq!(Endpoint::parse("cups.example").host(), "cups.example:631");assert_eq!(Endpoint::parse("cups.example:6310").host(), "cups.example:6310");assert_eq!(Endpoint::parse("127.0.0.1:6310").host(), "127.0.0.1:6310");- // What the user is shown is written the same way.+ // A scoped address keeps its zone id, but the authority writes it "%25"-escaped: a bare "%" is+ // not valid inside an authority, and the escaped form is what CUPS and curl-style ipp:// URIs+ // use. The host itself stays raw, because that is what the resolver gets.+ assert_eq!(Endpoint::parse("fe80::1%3:631").host(), "[fe80::1%253]:631");+ assert_eq!(Endpoint::parse("[fe80::1%3]:6310").host(), "[fe80::1%253]:6310");+ assert_eq!(Endpoint::parse("fe80::1%eth0:631").host(), "[fe80::1%25eth0]:631");+ assert_eq!(Endpoint::parse("fe80::1%3:631"), Endpoint::Tcp("fe80::1%3".into(), 631));+ // What the user is shown is written the same way, with the zone exactly as it was typed.assert_eq!(Endpoint::parse("::1").to_string(), "[::1]:631");assert_eq!(Endpoint::parse("cups.example:6310").to_string(), "cups.example:6310");+ assert_eq!(Endpoint::parse("fe80::1%3:631").to_string(), "[fe80::1%3]:631");}#[test]