Web Technology Basics
To put the Japanese character "あ" into a URL query, the byte sequence representing it in UTF-8 (E3 81 82) is percent-encoded. Which of the following is the correct result?
- A%E3%81%82
- B%u3042
- Cあ
Show answer and explanation
Answer: A. %E3%81%82
In percent-encoding, when characters that cannot be written in a URL as they are, or characters with special meanings such as / ? # &, are used as data, the characters are turned into bytes and each byte is written as "%" followed by two hexadecimal digits. "あ" is the three bytes E3 81 82 in UTF-8, so it becomes %E3%81%82. A space becomes %20 (in the form submission format, + is also used). In JavaScript, the encodeURIComponent function performs this conversion.
- A. Correct. Each of the three bytes is written in the form %XX.
- B. This notation uses the Unicode code point (U+3042) and is what JavaScript's old escape function outputs, but it is not a standard notation for URLs.
- C. This is a character reference, the HTML notation for writing a character by its number; it is not URL percent-encoding.