encodeuricomponent vs encodeuri

mdn example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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)
  • 새롭게 url을 생성하는 과정에서는 encodeURIComponent를 쓰면될 것 같다

참고

Author

chinsung

Posted on

2022-01-16

Updated on

2022-01-16

Licensed under

댓글