code wiki / (root) / nx_url_canonical.nx

nx_url_canonical.nx

buildroot/runtime/nx_url_canonical.nx

5517 B155 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind tooltopic url
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_url_canonical.nx nx_totp_uri.nx

imports: nx_syscalls.nx

imported by: nx_totp_uri.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap url_encode_component url_unreserved url_hex_upper url_decode url_hex_val

structs

none

consts

33const URL_ERR_BAD_ESCAPE: i64 = -1
34const URL_ERR_TRUNCATED: i64 = -2

functions

37func url_unreserved(c: i64) -> i64
49func url_hex_upper(n: i64) -> i64
55func url_hex_val(c: i64) -> i64
called by 1: url_decode
65func url_encode_component(in_bytes: *u8, n: i64, out: *u8) -> i64
86func url_encode_path(in_bytes: *u8, n: i64, out: *u8) -> i64
113func url_decode(in_bytes: *u8, n: i64, out: *u8) -> i64
called by 1: main calls 1: url_hex_val
138func main() -> i64