query() - > Map<string, Array<string>>- Module
- std.
url - Receiver
- URL
- Minimum arity
- 0
- Maximum arity
- 0
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.url in language mode 5.21.
The current compiler selects std/url.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1090 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 59 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1090 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 453 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1296 - compiler/crates/topaz_value/src/value/members.rs at
b48527d0a174· 282
Receiver
URL
Parameter constraints
URL.query returns a new Map from decoded names to arrays of decoded values. A missing query and an empty query both produce an empty map.
Query decoding follows application/x-www-form-urlencoded parsing. Ampersands separate fields. Empty fields between separators are skipped. The first equals sign separates each name from its value. A field without that sign has an empty value.
An explicit empty name is retained. A plus sign decodes to an ASCII space. Valid percent escapes decode to bytes and those bytes decode as UTF-8. Malformed percent escapes remain literal text and invalid UTF-8 sequences use the replacement character.
Repeated names are grouped after decoding. Values retain encounter order. Map keys retain the order in which their decoded names first appear. No sorting, deduplication, or comma splitting occurs.
The returned Map and its value arrays follow collection value semantics. URL.toString preserves the stored serialized query rather than serializing this map.
Reading a query evaluates its receiver once and performs no external operation. A constructed URL can always produce its query map. Query decoding does not return a diagnostic or a Result error.
Related rule: Decode query fields into an independent mapResult
The declared result type is Map<string, Array<string>>.
Effects
Failures
Result and effects
LinkReturns an independent map of form-decoded query names and ordered value arrays.
Resolved contracts
LinkRelated entries
LinkDecode query fields into an independent map
LinkDecode query fields into an independent map
URL.query returns a new Map from decoded names to arrays of decoded values. A missing query and an empty query both produce an empty map.
Query decoding follows application/x-www-form-urlencoded parsing. Ampersands separate fields. Empty fields between separators are skipped. The first equals sign separates each name from its value. A field without that sign has an empty value.
An explicit empty name is retained. A plus sign decodes to an ASCII space. Valid percent escapes decode to bytes and those bytes decode as UTF-8. Malformed percent escapes remain literal text and invalid UTF-8 sequences use the replacement character.
Repeated names are grouped after decoding. Values retain encounter order. Map keys retain the order in which their decoded names first appear. No sorting, deduplication, or comma splitting occurs.
The returned Map and its value arrays follow collection value semantics. URL.toString preserves the stored serialized query rather than serializing this map.
Reading a query evaluates its receiver once and performs no external operation. A constructed URL can always produce its query map. Query decoding does not return a diagnostic or a Result error.
Why
Query syntax has its own escaping rules and permits repeated names. Grouped arrays preserve every value while immutable URLs keep query inspection from silently rewriting a link.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1570 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1601 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1745 - url.bs at
845bafca22fb· URL parsing and serialization and form parsing -
topaz.stdlib.contract.url-queryatworking-tree - topaz.decision.url-standard.1 at
topaz.decisi
Decode repeated query fields and preserve their value order
Linkimport std.url { URL }import std.iomatch (URL.parse("https://example.com/?q=a+b&q=%ED%95%9C&empty&x=a=b&=blank")) {case Ok(value) => {let fields = value.query()for name in (["q", "empty", "x", ""]) {match (fields.get(name)) {case Some(values) => {for item in (values) {io.writeLine("{name}={item}")}}case None() => io.writeLine("missing")}}}case Err(_) => io.writeLine("parse failed")}
q=a b q=한 empty= x=a=b =blank
Expected result
Expected result
Execution completes. Exit code 0.
q=a bq=한empty=x=a=b=blank
Source evidence
- compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1570 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1601 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1745 - url.bs at
845bafca22fb· URL parsing and serialization and form parsing -
topaz.stdlib.contract.url-queryatworking-tree - topaz.decision.url-standard.1 at
topaz.decisi
Skip empty separators while retaining an explicit empty field
Linkimport std.url { URL }import std.iofor text in (["https://example.com/", "https://example.com/?", "https://example.com/?&&a=1&&", "https://example.com/?="]) {match (URL.parse(text)) {case Ok(value) => {let fields = value.query()let hasEmptyName = fields.containsKey("")io.writeLine("{fields.length}:{hasEmptyName}")}case Err(_) => io.writeLine("parse failed")}}
0:false 0:false 1:false 1:true
Expected result
Expected result
Execution completes. Exit code 0.
0:false0:false1:false1:true
Source evidence
- compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1570 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1601 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1745 - url.bs at
845bafca22fb· URL parsing and serialization and form parsing -
topaz.stdlib.contract.url-queryatworking-tree - topaz.decision.url-standard.1 at
topaz.decisi
Keep malformed percent escapes as query data
Linkimport std.url { URL }import std.iofor text in (["https://example.com/?x=%", "https://example.com/?x=%GG"]) {match (URL.parse(text)) {case Ok(value) => {match (value.query().get("x")) {case Some(values) => io.writeLine(values[0])case None() => io.writeLine("missing")}}case Err(_) => io.writeLine("parse failed")}}
% %GG
Expected result
Expected result
Execution completes. Exit code 0.
%%GG
Source evidence
- compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1570 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1601 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1745 - url.bs at
845bafca22fb· URL parsing and serialization and form parsing -
topaz.stdlib.contract.url-queryatworking-tree - topaz.decision.url-standard.1 at
topaz.decisi
Replace an invalid decoded UTF-8 byte in a query field
Linkimport std.url { URL }import std.iomatch (URL.parse("https://example.com/?x=%ff")) {case Ok(value) => {match (value.query().get("x")) {case Some(values) => io.writeLine(values[0])case None() => io.writeLine("missing")}io.writeLine(value.toString())}case Err(_) => io.writeLine("parse failed")}
� https://example.com/?x=%ff
Expected result
Expected result
Execution completes. Exit code 0.
�https://example.com/?x=%ff
Source evidence
- compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1570 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1601 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1745 - url.bs at
845bafca22fb· URL parsing and serialization and form parsing -
topaz.stdlib.contract.url-queryatworking-tree - topaz.decision.url-standard.1 at
topaz.decisi
Mutate a query snapshot without changing its URL
Linkimport std.url { URL }import std.iomatch (URL.parse("https://example.com/?k=first")) {case Ok(value) => {let mut snapshot = value.query()snapshot.insert("k", ["changed", "again"])snapshot.insert("extra", ["local"])let reread = value.query()io.writeLine("{reread.length}")match (reread.get("k")) {case Some(values) => {for item in (values) {io.writeLine(item)}}case None() => io.writeLine("missing")}io.writeLine(value.toString())}case Err(_) => io.writeLine("parse failed")}
1 first https://example.com/?k=first
Expected result
Expected result
Execution completes. Exit code 0.
1firsthttps://example.com/?k=first
Source evidence
- compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1570 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1601 - compiler/crates/topaz_value/src/value/builtins/path_regex_url.rs at
912a5e86e1f9· 1745 - url.bs at
845bafca22fb· URL parsing and serialization and form parsing -
topaz.stdlib.contract.url-queryatworking-tree - topaz.decision.url-standard.1 at
topaz.decisi