Baseline Widely available
encodeURIComponent()
í¨ìë URIì í¹ì í 문ì를 UTF-8ë¡ ì¸ì½ë©í´ íë, ë, ì
, í¹ì ë¤ ê°ì ì°ìë ì´ì¤ì¼ì´í 문ìë¡ ëíë
ëë¤. (ë ê°ì ë리 문ìë¡ ì´ë£¨ì´ì§ 문ìë§ ì´ì¤ì¼ì´í 문ì ë¤ ê°ë¡ ë³íë©ëë¤.)
// 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"
구문 매ê°ë³ì ë°í ê°
주ì´ì§ 문ìì´ì URI 구ì±ììë¡ì ì¸ì½ë©í ìë¡ì´ 문ìì´.
ì¤ëªencodeURIComponent()
ë ë¤ì 문ì를 ì ì¸í 문ì를 ì´ì¤ì¼ì´í í©ëë¤.
Not Escaped: A-Z a-z 0-9 - _ . ! ~ * ' ( )
encodeURIComponent()
ì encodeURI()
ì ì°¨ì´ë ë¤ìê³¼ ê°ìµëë¤.
var set1 = ";,/?:@&=+$"; // Reserved Characters
var set2 = "-_.!~*'()"; // Unescaped Characters
var set3 = "#"; // Number Sign
var set4 = "ABC abc 123"; // Alphanumeric Characters + Space
console.log(encodeURI(set1)); // ;,/?:@&=+$
console.log(encodeURI(set2)); // -_.!~*'()
console.log(encodeURI(set3)); // #
console.log(encodeURI(set4)); // ABC%20abc%20123 (the space gets encoded as %20)
console.log(encodeURIComponent(set1)); // %3B%2C%2F%3F%3A%40%26%3D%2B%24
console.log(encodeURIComponent(set2)); // -_.!~*'()
console.log(encodeURIComponent(set3)); // %23
console.log(encodeURIComponent(set4)); // ABC%20abc%20123 (the space gets encoded as %20)
ìì-íì ìì ì´ë£¨ì§ ìì ë¨ì¼ ë리 문ì를 ì¸ì½ë© ìëíë©´ URIError
ê° ë°ìí©ëë¤.
// high-low pair ok
console.log(encodeURIComponent("\uD800\uDFFF"));
// lone high surrogate throws "URIError: malformed URI sequence"
console.log(encodeURIComponent("\uD800"));
// lone low surrogate throws "URIError: malformed URI sequence"
console.log(encodeURIComponent("\uDFFF"));
encodeURIComponent()
를 ì¬ì©í´, ìë²ì POST
ë¡ ìì²í ìì íë를 ì¸ì½ë© íì¸ì. ì
ë ¥ ì¤ ìëì¹ ìê² ìì±ë ì ìë HTML í¹ì ê°ì²´ ë±ì "&"
문ì를 ì²ë¦¬í ì ììµëë¤.
ì를 ë¤ì´ ì¬ì©ìê° ì
ë ¥í "Jack & Jill"
ì "Jack & Jill"
ë¡ ì¸ì½ë© ë©ëë¤. encodeURIComponent()
를 ì¬ì©íì§ ììë¤ë©´ ìë²ê° ì°í¼ìë를 ìë¡ì´ íëì ììì¼ë¡ ì¸ìí ì ìì¼ë¯ë¡ ë°ì´í°ì 무결ì±ì í´ì¹ ì ììµëë¤.
application/x-www-form-urlencoded
ì ì¤íì´ì¤ë "+"
ë¡ ì¹íëì´ì¼ íë¯ë¡, encodeURIComponent()
ì ê²°ê³¼ì ì¶ê°ë¡ "%20"
ì "+"
ë¡ ë°ê¾¸ì¸ì.
ë¹ë¡ URIì 구ë¶ìë¡ì íìíë ì¬ì©ì²ë ìì§ë§, ê·¸ë¼ìë !
, '
, (
, )
, *
ì ì¶ê°ë¡ ìì½íë RFC 3986ì ì격íê² ë°ë¥´ë ¤ë©´ ìëì ì½ë를 ì¬ì©í´ë³´ì¸ì.
function fixedEncodeURIComponent(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return "%" + c.charCodeAt(0).toString(16);
});
}
ìì
ë¤ì ìì ë UTF-8 Content-Disposition
ê³¼Link
ìë² ìëµ í¤ëìì (UTF-8 íì¼ ì´ë¦ ë±ì ì´ì ë¡) íìí 문ì ì¸ì½ë© ë°©ë²ì ë³´ì
ëë¤.
var fileName = "my file(2).txt";
var header =
"Content-Disposition: attachment; filename*=UTF-8''" +
encodeRFC5987ValueChars(fileName);
console.log(header);
// logs "Content-Disposition: attachment; filename*=UTF-8''my%20file%282%29.txt"
function encodeRFC5987ValueChars(str) {
return (
encodeURIComponent(str)
// Note that although RFC3986 reserves "!", RFC5987 does not,
// so we do not need to escape it
.replace(/['()]/g, escape) // i.e., %27 %28 %29
.replace(/\*/g, "%2A")
// 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, unescape)
);
}
// here is an alternative to the above function
function encodeRFC5987ValueChars2(str) {
return (
encodeURIComponent(str)
// Note that although RFC3986 reserves "!", RFC5987 does not,
// so we do not need to escape it
.replace(/['()*]/g, (c) => "%" + c.charCodeAt(0).toString(16)) // i.e., %27 %28 %29 %2a (Note that valid encoding of "*" is %2A
// which necessitates calling toUpperCase() to properly encode)
// 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)),
)
);
}
ëª
ì¸ ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
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