When does YAML actually need to be URL-encoded?
Whenever you build a "share this config" or "preview this manifest" link. Configuration UIs for Kubernetes (kubectl gateway), Helm chart browsers, GitOps tools, GitHub Actions playgrounds, and IDE extensions often pass YAML through query parameters. The colons, newlines, and hash characters in YAML all conflict with URL syntax — percent-encoding removes the conflict.
Why does the encoded output look so much longer than the YAML input?
Most YAML characters expand. A colon becomes %3A (3 chars from 1), a newline becomes %0A (3 from 1), a leading space becomes %20 (3 from 1), and an indented block uses many leading spaces. A typical 200-byte YAML manifest balloons past 600 bytes after encoding. Plan accordingly — most browsers cap URLs around 2,000–8,000 characters.
Will indentation survive the round-trip?
Yes, exactly. Every leading space encodes to %20 and decodes back to a literal space; every newline encodes to %0A. The decoded document is byte-for-byte identical to the source — important because a single missing space silently changes a YAML document's structure.
encodeURIComponent vs encodeURI — which one does this use?
encodeURIComponent. It escapes every URL-structural delimiter (?, &, #, /, :, =, +) — exactly what a parameter value needs. encodeURI would leave colons and slashes alone, which is wrong for embedded YAML where a key like apiVersion: v1 must not be interpreted as part of the URL structure.
Should I YAML-serialise before encoding, or encode raw text?
First produce a YAML string from your data structure (the way Kubernetes, Helm, or your own tool would), then URL-encode the YAML string. Encoding a raw object directly would either skip serialisation entirely or use a different format. Serialisation comes first; URL encoding always last.
How are non-ASCII characters handled?
encodeURIComponent converts each character to its UTF-8 byte sequence and then percent-encodes every byte. So é becomes %C3%A9, € becomes %E2%82%AC, and 🚀 becomes %F0%9F%9A%80. The output is always plain ASCII safe for any URL.
What about the newline encoding — %0A vs %0D%0A?
YAML on Unix uses LF newlines, encoded as %0A. Files saved on Windows use CRLF — %0D%0A. Both decode back to YAML the parser will accept, but YAML parsers vary on whether they normalise \r\n. If you generate the YAML in JavaScript directly, you get LF and the cleaner %0A encoding.
Is my YAML uploaded to a server?
No. encodeURIComponent runs in your browser. Kubernetes secrets, Helm values, Compose passwords, and any embedded credentials never leave the page. Verify in DevTools → Network — no request fires when you click Encode.