1/* There are 11 characters which are not encoded by encodeURI,
2but encoded by encodeURIComponent. */
3
4encodeURI("test uri");
5// "test%20uri"
6encodeURI("test uri");
7// "test%20uri"
8
9encodeURI("test uri/with a slash");
10// "test%20uri/with%20a%20slash"
11encodeURIComponent("test uri/with a slash");
12// "test%20uri%2Fwith%20a%20slash"
1var myUrl = "http://www.image.com/?username=unknown&password=unknown";
2var encodedURL= "http://www.foobar.com/foo?imageurl=" + encodeURIComponent(myUrl);
3
1var set1 = ";,/?:@&=+$"; // Reserved Characters
2var set2 = "-_.!~*'()"; // Unescaped Characters
3var set3 = "#"; // Number Sign
4var set4 = "ABC abc 123"; // Alphanumeric Characters + Space
5
6console.log(encodeURI(set1)); // ;,/?:@&=+$
7console.log(encodeURI(set2)); // -_.!~*'()
8console.log(encodeURI(set3)); // #
9console.log(encodeURI(set4)); // ABC%20abc%20123 (the space gets encoded as %20)
10
11console.log(encodeURIComponent(set1)); // %3B%2C%2F%3F%3A%40%26%3D%2B%24
12console.log(encodeURIComponent(set2)); // -_.!~*'()
13console.log(encodeURIComponent(set3)); // %23
14console.log(encodeURIComponent(set4)); // ABC%20abc%20123 (the space gets encoded as %20)
15
16