Baseline Widely available
encodeURIComponent()
颿°ã¯ URI ããç¹å®ã®æåã®åã¤ã³ã¹ã¿ã³ã¹ãããã®æåã® UTF-8 ã¨ã³ã³ã¼ãæ¹å¼ã表ã 1 ã¤ãã 4 ã¤ã®ã¨ã¹ã±ã¼ãã·ã¼ã±ã³ã¹ã§ç½®ãæãããã¨ã§ã¨ã³ã³ã¼ããã¾ã (2 ã¤ã®ãµãã²ã¼ãæåã§æ§æãããæåã®å ´å㯠4 ã¤ã®ã¨ã¹ã±ã¼ãã·ã¼ã±ã³ã¹ã«ãªãã¾ã)ã encodeURI()
ã¨æ¯è¼ããã¨ããã®é¢æ°ã¯ URI æ§æã®ä¸é¨ãå«ãããå¤ãã®æåãã¨ã³ã³ã¼ããã¾ãã
// Encodes characters such as ?,=,/,&,:
console.log(`?x=${encodeURIComponent("test?")}`);
// Expected output: "?x=test%3F"
console.log(`?x=${encodeURIComponent("ÑеллÑ")}`);
// Expected output: "?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"
æ§æ
encodeURIComponent(uriComponent)
弿°
uriComponent
URI ã®é¨åï¼ãã¹ãã¯ã¨ãªã¼æååããã©ã°ã¡ã³ããªã©ï¼ã¨ãã¦ã¨ã³ã³ã¼ããããæååãä»ã«ãæååã«å¤æãããå¤ãããã¾ãã
ä¸ããããæååã表ã URI æ§æè¦ç´ ã¨ãã¦ã¨ã³ã³ã¼ããããæ°ããæååã§ãã
ä¾å¤URIError
uriComponent
ã«å¤ç«ãµãã²ã¼ããããã¨çºçãã¾ãã
encodeURIComponent()
ã¯ã°ãã¼ãã«ãªãã¸ã§ã¯ãã®é¢æ°ããããã£ã§ãã
encodeURIComponent
㯠encodeURI()
ã§èª¬æããã¦ããã®ã¨åãã¨ã³ã³ã¼ãã£ã³ã°ã¢ã«ã´ãªãºã ã使ç¨ãã¾ããä¸è¨ãé¤ããã¹ã¦ã®æåãã¨ã¹ã±ã¼ããã¾ãã
AâZ aâz 0â9 - _ . ! ~ * ' ( )
encodeURI()
ã¨æ¯è¼ããã¨ã encodeURIComponent()
ã¯ããå¤ãã®æåã»ãããã¨ã¹ã±ã¼ããã¾ãã encodeURIComponent()
ã¯ããµã¼ãã¼ã« POST
ããããã©ã¼ã ããã¦ã¼ã¶ã¼ãå
¥åããé
ç®ã«å¯¾ãã¦ä½¿ç¨ãã¾ããããã¯ãæååç
§ããã®ä»ã¨ã³ã³ã¼ã/ãã³ã¼ããè¦æ±ãããæåã«ã¤ãã¦ã ãã¼ã¿å
¥åä¸ã«ä¸ç¨æã«çºçããå¯è½æ§ã®ããè¨å·ãã¨ã³ã³ã¼ããã¾ããä¾ãã°ãã¦ã¼ã¶ã¼ã Jack & Jill
ã¨å
¥åããå ´åãããã¹ã㯠Jack & Jill
ã¨ã¨ã³ã³ã¼ããããå¯è½æ§ãããã¾ããencodeURIComponent()
ã使ç¨ããªãå ´å㯠"&" ãæ°ãããã£ã¼ã«ãã®å§ã¾ãã¨ãã¦ãµã¼ãã¼ä¸ã§è§£éããããã¼ã¿ã®å®å
¨æ§ãæãªãããå¯è½æ§ãããã¾ãã
application/x-www-form-urlencoded
ã§ã¯ãã¹ãã¼ã¹ã¯ +
ã«ç½®æããã¾ãããã®ãããencodeURIComponent()
ã«ããç½®æã«å ã㦠%20
ã +
ã«ç½®ãæãããã¨ãæã¾ããããããã¾ããã
次ã®ä¾ã¯ããµã¼ãã¼ã¬ã¹ãã³ã¹ãããã¼å¼æ°ã® Content-Disposition
ã Link
ã§ (UTF-8 ãããªããã¡ã¤ã«åãªã©ã«) å¿
è¦ã¨ãªãç¹å¥ãª UTF-8 ã¨ã³ã³ã¼ãã£ã³ã°ãæä¾ãã¾ãã
const fileName = "my file(2).txt";
const header = `Content-Disposition: attachment; filename*=UTF-8''${encodeRFC5987ValueChars(
fileName,
)}`;
console.log(header);
// "Content-Disposition: attachment; filename*=UTF-8''my%20file%282%29.txt"
function encodeRFC5987ValueChars(str) {
return (
encodeURIComponent(str)
// The following creates the sequences %27 %28 %29 %2A (Note that
// the valid encoding of "*" is %2A, which necessitates calling
// toUpperCase() to properly encode). Although RFC3986 reserves "!",
// RFC5987 does not, so we do not need to escape it.
.replace(
/['()*]/g,
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
)
// The following are not required for percent-encoding per RFC5987,
// so we can allow for a little better readability over the wire: |`^
.replace(/%(7C|60|5E)/g, (str, hex) =>
String.fromCharCode(parseInt(hex, 16)),
)
);
}
RFC3986 ã®ã¨ã³ã³ã¼ãã£ã³ã°
ææ°ã® RFC3986 ã§ã¯ã !
, '
, (
, )
, *
ãããã¨ããããã®æåãæ£å¼ãª URI åºåãæåã¨ãã¦ä½¿ç¨ããã¦ããªãã¨ãã¦ãäºç´ãã¦ãã¾ãã IPv6 ã® URI æ§æã®ä¸é¨ã§ãã [
㨠]
ãã¨ã³ã³ã¼ããã¾ãã RFC3986 ã«æºæ ãã encodeURI
ã®å®è£
ã§ã¯ãããããã¨ã¹ã±ã¼ããã¹ãã§ã¯ããã¾ããããã㯠encodeURI() ã®ä¾ã§ç¤ºããã¦ãã¾ãã
function encodeRFC3986URIComponent(str) {
return encodeURIComponent(str).replace(
/[!'()*]/g,
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
);
}
å¤ç«ãµãã²ã¼ãã®ã¨ã³ã³ã¼ãã«ããä¾å¤
ä¸ä½ã»ä¸ä½ã®ãã¢ã§ãªããµãã²ã¼ãæåãã¨ã³ã³ã¼ããããã¨ããå ´å URIError
ãçºçãã¾ãã
// ä¸ä½ã»ä¸ä½ã®æ£ãããã¢
encodeURIComponent("\uD800\uDFFF"); // "%F0%90%8F%BF"
// ä¸ä½ã®ã¿ã§ãã "URIError: malformed URI sequence" ãçºç
encodeURIComponent("\uD800");
// ä¸ä½ã®ã¿ã§ãã "URIError: malformed URI sequence" ãçºç
encodeURIComponent("\uDFFF");
String.prototype.toWellFormed()
ã使ç¨ãããã¨ãã§ãã¾ããããã¯å¤ç«ãµãã²ã¼ãã Unicode ç½®ææå (U+FFFD) ã«ç½®ãæãããã¨ã§ããã®ã¨ã©ã¼ãé¿ãããã¨ãã§ãã¾ããã¾ãã String.prototype.isWellFormed()
ã使ç¨ãããã¨ã§ãæååã encodeURIComponent()
ã«æ¸¡ãåã«ãå¤ç«ãµãã²ã¼ããå«ã¾ãã¦ãããã©ããã調ã¹ããã¨ãã§ãã¾ãã
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4