encodeURI()
í¨ìë URIìì í¹ë³í ë»ì ê°ì§ 문ì(ìì½ ë¬¸ì)ë ì¸ì½ë© íì§ ììµëë¤. ìë ìì ë "URI ëì"ì´ í¬í¨í ì ìë 모ë ë¶ë¶ì ë´ê³ ììµëë¤. ì¼ë¶ 문ìê° ì´ë¤ ë°©ìì¼ë¡ í¹ë³í ì미를 주ì
íê³ ìëì§ ì ì´í´ë³´ì¸ì.
http://username:password@www.example.com:80/path/to/file.php?foo=316&bar=this+has+spaces#anchor
ë°ë¼ì encodeURI()
ë ìì í URI를 íì±íëë° íìí 문ìë ì¸ì½ë© íì§ ììµëë¤. ëí, ìì½ë 목ì ì ê°ì§ì§ë ìì§ë§ URIê° ê·¸ëë¡ í¬í¨í ì ìë ëª ê°ì§ 문ì("ë¹ìì½ íì")ë ì¸ì½ë© íì§ ììµëë¤. (RFC 2396ì ì°¸ê³ íì¸ì)
encodeURI()
ë ë¤ì 문ì를 ì ì¸í 문ì를 ì´ì¤ì¼ì´í í©ëë¤.
ì´ì¤ì¼ì´í íì§ ìë 문ì: A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #
encodeURI()
ì encodeURIComponent()
ì ì°¨ì´ë ë¤ìê³¼ ê°ìµëë¤.
var set1 = ";,/?:@&=+$#"; // ìì½ ë¬¸ì
var set2 = "-_.!~*'()"; // ë¹ìì½ íì
var set3 = "ABC abc 123"; // ìíë²³ ë° ì«ì, 공백
console.log(encodeURI(set1)); // ;,/?:@&=+$#
console.log(encodeURI(set2)); // -_.!~*'()
console.log(encodeURI(set3)); // ABC%20abc%20123 (공백ì %20ì¼ë¡ ì¸ì½ë©)
console.log(encodeURIComponent(set1)); // %3B%2C%2F%3F%3A%40%26%3D%2B%24%23
console.log(encodeURIComponent(set2)); // -_.!~*'()
console.log(encodeURIComponent(set3)); // ABC%20abc%20123 (공백ì %20ì¼ë¡ ì¸ì½ë©)
encodeURI()
í¼ììë XMLHttpRequest
ë±ì´ ì¬ì©í , ì í©í HTTP GET
ê³¼ POST
ìì²ì 구ì±í ì ììµëë¤. GET
ê³¼ POST
ìì í¹ë³í 문ìë¡ ì·¨ê¸íë "&"
, "+"
, "="
를 ì¸ì½ë© íì§ ì기 ë문ì
ëë¤. ê·¸ë¬ë encodeURIComponent()
ë ì ì¸ ë¬¸ìë ì¸ì½ë© ëìì í¬í¨í©ëë¤.
ìì-íì ìì ì´ë£¨ì§ ìì ë¨ì¼ ë리 문ì를 ì¸ì½ë© ìëíë©´ 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"));
ëí, URLì ë³´ë¤ ìµì RFCì¸ RFC3986ì ë°ë¥´ê³ ì íë¤ë©´, ëê´í¸ê° IPv6 ì§ìì ìí´ ì¶ê°ë¡ ìì½ë¨ì ë°ë¼ encodeURI()
ê° ì¸ì½ë©íì§ ìì¼ë¯ë¡ URLì ìì±í ë 주ìí´ì¼ í©ëë¤. ë¤ì ìì ì½ëê° ëìì´ ë ìë ììµëë¤.
function fixedEncodeURI(str) {
return encodeURI(str).replace(/%5B/g, "[").replace(/%5D/g, "]");
}
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