url.nx
buildroot/runtime/url.nx
about
url.nx -- URL percent-encoding + decoding (RFC 3986).
Used by: HTTP query strings, path segments, form-urlencoded
POST bodies, JWT segments. Complements base64.nx / hex.nx for
the URL-safe text-encoding niche.
Encoding rules (RFC 3986 ยง2.3):
Unreserved: A-Z a-z 0-9 - . _ ~ (encoded as-is)
Reserved: : / ? # [ ] @ ! $ & ' ( ) * + , ; =
-- reserved chars DEPEND on context. We offer two encoders:
url_encode_component -- encodes everything reserved
url_encode_path -- preserves / for path segments
All other bytes: encoded as %HH (two uppercase hex digits).
Invariants:
UR1 Output is deterministic: same input -> same bytes.
UR2 Decoder rejects malformed sequences (%X or %XY where Y
isn't hex) with a negative return. No silent skip.
UR3 Decoder accepts both upper and lower case hex digits.
UR4 Round-trip exact for any byte sequence:
decode(encode(x)) == x
UR5 Encoder never outputs non-ASCII; caller always gets
7-bit safe text.
dependencies 1 imports · 1 importers
imports: syscalls.nx
imported by: totp_uri.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 27 | const URL_ERR_BAD_ESCAPE: i64 = -1 |
| 28 | const URL_ERR_TRUNCATED: i64 = -2 |
functions
| 31 | func url_unreserved(c: i64) -> i64 { |
| 43 | func url_hex_upper(n: i64) -> i64 { |
| 49 | func url_hex_val(c: i64) -> i64 {
called by 1: url_decode |
| 59 | func url_encode_component(in_bytes: *u8, n: i64, out: *u8) -> i64 { |
| 80 | func url_encode_path(in_bytes: *u8, n: i64, out: *u8) -> i64 { |
| 107 | func url_decode(in_bytes: *u8, n: i64, out: *u8) -> i64 { |
| 132 | func main() -> i64 { |