query() - > Map<string, Array<string>>- 수신자
- URL
- 최소 인자 수
- 0
- 최대 인자 수
- 0
Declaration and parameters
링크사용 조건
기본 포함 · 미정
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.
수신자
URL
매개변수 제약
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.
관련 규칙 · Decode query fields into an independent map →결과
The declared result type is Map<string, Array<string>>.
효과
실패
Result and effects
링크Returns an independent map of form-decoded query names and ordered value arrays.
Resolved contracts
링크Related entries
링크Decode query fields into an independent map
링크Decode 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.
이유
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.
Decode repeated query fields and preserve their value order
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
q=a bq=한empty=x=a=b=blank
Skip empty separators while retaining an explicit empty field
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
0:false0:false1:false1:true
Keep malformed percent escapes as query data
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
%%GG
Replace an invalid decoded UTF-8 byte in a query field
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
�https://example.com/?x=%ff
Mutate a query snapshot without changing its URL
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
1firsthttps://example.com/?k=first