5
var assert = require('assert');
6
var decode = require('../decode');
8
function encodeBinary(str) {
11
str = str.replace(/\s+/g, '');
13
result = '%' + ('0' + parseInt(str.slice(-8), 2).toString(16)).slice(-2) + result;
14
str = str.slice(0, -8);
30
'11000111 01010101': false,
31
'11100011 01010101': false,
32
'11110001 01010101': false,
35
'11000111 11000000': false,
36
'11100011 11000000': false,
37
'11110001 11000000': false,
40
'11100011 10010101 01010101': false,
41
'11110001 10010101 01010101': false,
44
'11110001 10010101 10010101 01010101': false,
47
'11000111 10101010': true,
48
'11100011 10101010 10101010': true,
49
'11110001 10101010 10101010 10101010': true,
52
'11000010 10000000': true,
53
'11100000 10100000 10000000': true,
56
'11000001 10111111': false,
57
'11100000 10011111 10111111': false,
58
'11000001 10000000': false,
59
'11100000 10010000 10000000': false,
62
'11011111 10111111': true,
63
'11101111 10111111 10111111': true,
65
'11110000 10010000 10000000 10000000': true,
66
'11110000 10010000 10001111 10001111': true,
67
'11110100 10001111 10110000 10000000': true,
68
'11110100 10001111 10111111 10111111': true,
71
'11110000 10001111 10111111 10111111': false,
74
'11110100 10010000 10000000 10000000': false,
75
'11110100 10011111 10111111 10111111': false,
78
'11101101 10011111 10111111': true,
79
'11101101 10100000 10000000': false,
80
'11101101 10111111 10111111': false,
81
'11101110 10000000 10000000': true
84
describe('decode', function() {
85
it('should decode %xx', function() {
86
assert.equal(decode('x%20xx%20%2520'), 'x xx %20');
89
it('should not decode invalid sequences', function() {
90
assert.equal(decode('%2g%z1%%'), '%2g%z1%%');
93
it('should not decode reservedSet', function() {
94
assert.equal(decode('%20%25%20', '%'), ' %25 ');
95
assert.equal(decode('%20%25%20', ' '), '%20%%20');
96
assert.equal(decode('%20%25%20', ' %'), '%20%25%20');
99
describe('utf8', function() {
100
Object.keys(samples).forEach(function(k) {
104
str = encodeBinary(k);
107
res1 = decodeURIComponent(str);
115
assert.notEqual(res2.indexOf('\ufffd'), -1);
117
assert.equal(res1, res2);
118
assert.equal(res2.indexOf('\ufffd'), -1);