Regulatory Verification (Nov 2026):
100% Client-Side Privacy
Skip to main content
Developer Handbook • 9 min read • Statutory Review: 2026-11-22 • 100% Verified Formulation

URL Encoding, Percent-Encoding & RFC 3986 Standards: Form-Urlencoded vs encodeURIComponent

A technical exploration of Uniform Resource Identifier (URI) syntax specifications, reserved vs unreserved characters, UTF-8 octet serialization, and query string encoding traps.

ST
Lead Developer & Publisher • Based in Bengaluru, India
Direct Answer in the First 100 Words

URL encoding (formally termed Percent-Encoding under IETF RFC 3986) replaces non-ASCII and reserved URI characters with a percent sign followed by two hexadecimal digits representing the character’s raw UTF-8 byte value. In JavaScript, encodeURI() preserves full URI structural delimiters (such as :, /, ?, #) and should be used on complete URL strings, whereas encodeURIComponent() encodes ALL structural delimiters and must be used on individual query parameter keys and values. The controversial convention of replacing spaces with a plus sign (+) applies strictly to application/x-www-form-urlencoded HTML form submissions, whereas standard RFC 3986 URIs mandate %20.

Key Takeaways & Regulatory Summary

  • RFC 3986 defines 66 "unreserved" characters that must never be encoded: A-Z, a-z, 0-9, hyphen (-), underscore (_), period (.), and tilde (~).
  • Reserved characters (such as ?, &, =, /, :, #) possess specific syntactical meaning as structural path, query, and fragment delimiters.
  • encodeURIComponent() must be applied to query values, not full URLs; applying it to a full URL corrupts https:// into https%3A%2F%2F.
  • The space character is encoded as %20 under RFC 3986; encoding spaces as plus (+) is valid only within form-urlencoded payloads.
  • Multi-byte Unicode characters (such as Hindi, Arabic, or emojis) generate multiple percent-encoded octets per character (e.g. 🇮🇳 = 8 bytes).
  • Modern backend frameworks (Express, Spring, FastAPI) can suffer Double Decoding security vulnerabilities if gateway firewalls decode URLs prematurely.

1. The Plus Sign (+) vs. %20 Controversy

One of the most persistent sources of confusion in web engineering is whether a space should be encoded as `%20` or `+`.

The answer stems from two conflicting historical specifications:

• RFC 3986 (Uniform Resource Identifier): The authoritative standard for all web URLs dictates that space must ALWAYS be encoded as `%20`. Under RFC 3986, a plus sign (`+`) is a reserved sub-delimiter representing a literal plus symbol.

• HTML 4 / WHATWG Form Specification: When an HTML `<form method="GET">` is submitted, the legacy browser specification encodes form fields using `application/x-www-form-urlencoded`. Under this specific legacy MIME standard, spaces are replaced with `+`.

This creates severe bugs in modern APIs: if you send `?tag=c++` and a naive server uses form-urlencoded decoding, it interprets the pluses as spaces, reading your tag as "c "! To prevent this ambiguity in REST APIs, modern web standards mandate standard RFC 3986 percent-encoding (`%20` for space, `%2B` for plus).

2. encodeURI() vs. encodeURIComponent(): The Crucial Distinction

JavaScript provides two native global functions for URI transformation:

• encodeURI(completeUrl): Encodes a complete URI string. It intentionally ignores structural delimiters: `A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #`. It is designed to take a full URL like `https://dmrs.in/tools/gst-calculator?name=tax calculator` and encode only the raw spaces into `%20`.

• encodeURIComponent(component): Encodes an individual parameter component. It encodes everything except `A-Z a-z 0-9 - _ . ! ~ * ' ( )`. It DOES encode `&`, `=`, `+`, `/`, `?`, and `:`. You must use this function whenever passing arbitrary user inputs, API keys, email addresses, or redirect URLs as query string values.

3. Multi-Byte Unicode and Emoji Encoding Mechanics

Legacy systems assumed characters were single 8-bit bytes (ASCII or Latin-1). Modern web standards mandate that percent-encoding operates on UTF-8 octets.

In UTF-8, characters use variable-length byte representations: standard English letters take 1 byte; Latin accented characters take 2 bytes; Indian scripts (Devanagari, Tamil, Kannada) take 3 bytes; and emojis take 4 bytes.

For example, the popular rocket emoji 🚀 has the Unicode code point U+1F680. In UTF-8, this is serialized into four raw hexadecimal bytes: `F0 9F 9A 80`. When passed through `encodeURIComponent("🚀")`, JavaScript outputs `%F0%9F%9A%80`. Web gateways and database decoders must reconstruct the four individual percent-encoded bytes back into a single continuous UTF-8 buffer before converting to string representations.

4. The Double-Decoding Vulnerability (Path Traversal & Security Hazards)

A critical cybersecurity flaw in web API architecture is Double Decoding (CWE-177). An attacker constructs a malicious payload to execute path traversal: `..%252f..%252fetc%252fpasswd`.

Notice the `%252f`. `%25` is the percent-encoding for a literal percent sign. When the incoming request hits an edge reverse proxy (such as Nginx or a cloud load balancer), the proxy decodes `%252f` once, transforming it into `%2f`. The proxy examines the path, sees no illegal slashes (`/`), and forwards the request to the upstream Node.js or Java application.

If the upstream application naively calls `decodeURIComponent()` a second time, `%2f` is decoded into a literal forward slash `/`, successfully triggering a directory traversal attack! To protect against double decoding, API gateways should enforce single canonical decoding passes and reject requests containing nested percent signs.

5. URLSearchParams: The Modern Web Standard API

Modern TypeScript and JavaScript applications should avoid manual string concatenation (`"?" + key + "=" + val`) in favor of the standard `URLSearchParams` Web API. When you append parameters via `params.set("query", "tax & finance")`, the engine automatically manages RFC-compliant percent-encoding, handles duplicate keys gracefully, and eliminates manual regex string splicing.

Practical Worked Example: Encoding an Indian Tax Calculation Query String with Special Characters and Hindi Text

A developer passes a search query containing ampersands, spaces, mathematical symbols, and Unicode Hindi characters through JavaScript encoding functions.

Input String ComponentRaw Character ValueencodeURI() OutputencodeURIComponent() OutputRFC 3986 Standard Octets
Protocol & Hosthttps://dmrs.in/toolshttps://dmrs.in/toolshttps%3A%2F%2Fdmrs.in%2Ftools (Corrupted!)Preserved as structural delimiters
Space Character" " (Literal Space)%20%20%20 (Hex 0x20)
Ampersand Delimiter&& (Preserved as query delimiter)%26 (Safely isolated as value data)%26 (Hex 0x26)
Equal Sign Operator== (Preserved as key-value delimiter)%3D (Safely isolated as value data)%3D (Hex 0x3D)
Plus Sign Character++ (Preserved)%2B%2B (Hex 0x2B)
Rupee Currency Symbol₹ (Indian Rupee)%E2%82%B9 (3 UTF-8 bytes)%E2%82%B9 (3 UTF-8 bytes)%E2%82%B9 (Hex E2 82 B9)
Hindi Word "कर" (Tax)कर%E0%A4%95%E0%A4%B0 (6 UTF-8 bytes)%E0%A4%95%E0%A4%B0 (6 UTF-8 bytes)Each Devanagari character is 3 bytes
Worked Calculation Conclusion: To construct a bulletproof URL, keep the base path unencoded and wrap every dynamic query parameter key and value inside encodeURIComponent(), producing https://dmrs.in/tools?search=%E0%A4%95%E0%A4%B0%20%26%20%E2%82%B9.

Reserved vs. Unreserved Characters Under RFC 3986

Exact categorization of ASCII octets governing URI parsing grammars.

Character ClassificationExact Character WhitelistSyntactical URI FunctionEncoding Requirement
Unreserved CharactersALPHA (A-Z, a-z), DIGIT (0-9), "-", "_", ".", "~"Literal data payloads; zero structural ambiguityMUST NOT be encoded; decoding must preserve them
General Delimiters (gen-delims)":", "/", "?", "#", "[", "]", "@"Separates URI components (scheme, authority, path, query, fragment)Must be encoded if appearing as literal payload data
Sub-Delimiters (sub-delims)"!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "="Separates elements within query strings and parametersMust be encoded inside parameter keys and values
Whitespace & Control CharactersSpace, Tabs, CRLF, ASCII 0-31 and 127Illegal in raw URIsMUST be percent-encoded (e.g. space = %20)
Non-ASCII Unicode OctetsAll characters > ASCII 127 (Devanagari, CJK, Emojis)Represents internationalized text in UTF-8Must be converted to UTF-8 bytes, then each byte percent-encoded

Mistakes I See Most Often from Practice

  • Applying encodeURI() to Query Values: encodeURI() does not encode "&" or "=". If your query value contains "AT&T", encodeURI preserves the ampersand, splitting your value into two broken query parameters.
  • Applying encodeURIComponent() to Complete URLs: Wrapping "https://dmrs.in" in encodeURIComponent() converts colons and slashes into "%3A%2F%2F", producing an un-navigable string.
  • Manual String Splicing with Pluses: Manually replacing spaces with pluses without encoding literal plus characters destroys mathematical symbols (+ becomes space).
  • Assuming URL Length is Unlimited: While HTTP specifications enforce no theoretical limit, web browsers and CDN edge caches (Cloudflare, AWS CloudFront) typically truncate URLs exceeding 2,048 or 4,096 characters.

Official Statutory & Technical References

Verify rules directly with primary statutory sources:

RFC 3986 Uniform Resource Identifier (URI): Generic Syntax

IETF standard specifying percent-encoding grammar, reserved sets, and normalizations.

Visit Source ↗

WHATWG URL Living Standard

Authoritative browser engineering standard defining URL, URLSearchParams, and query serialization.

Visit Source ↗
ST
Verified Technical Author & Publisher

Authored & Reviewed by SUMAN TR

Lead Developer & Publisher • Based in Bengaluru, India

Last Verified: 2026-11-12

SUMAN TR is a seasoned WordPress developer, technical SEO specialist, and web publisher based in Bengaluru, India. With over 8 years of hands-on experience designing high-speed digital architectures and custom web utilities, Suman focuses on creating zero-bloat client-side calculation engines and practical, jargon-free guides tailored to Indian financial and web standards.

Related Handbooks & Guidance