The querystring. unescape method in node. js is described as follows:
Method description:
This method can be used to override querystring. parse.
Syntax:
Copy codeThe Code is as follows:
Querystring. unescape
Receiving parameters:
None
Source code:
Copy codeThe Code is as follows:
// A safe fast alternative to decodeURIComponent
QueryString. unescapeBuffer = function (s, decodeSpaces ){
Var out = new Buffer (s. length );
Var state = 'Char '; // states: CHAR, HEX0, HEX1
Var n, m, hexchar;
For (var inIndex = 0, outIndex = 0; inIndex <= s. length; inIndex ++ ){
Var c = s. charCodeAt (inIndex );
Switch (state ){
Case 'Char ':
Switch (c ){
Case charCode ('% '):
N = 0;
M = 0;
State = 'h0 ';
Break;
Case charCode ('+ '):
If (decodeSpaces) c = charCode ('');
// Pass thru
Default:
Out [outIndex ++] = c;
Break;
}
Break;
Case 'hex0 ':
State = 'hex1 ';
Hexchar = c;
If (charCode ('0') <= c & c <= charCode ('9 ')){
N = c-charCode ('0 ');
} Else if (charCode ('A') <= c & c <= charCode ('F ')){
N = c-charCode ('A') + 10;
} Else if (charCode ('A') <= c & c <= charCode ('F ')){
N = c-charCode ('A') + 10;
} Else {
Out [outIndex ++] = charCode ('% ');
Out [outIndex ++] = c;
State = 'Char ';
Break;
}
Break;
Case 'hex1 ':
State = 'Char ';
If (charCode ('0') <= c & c <= charCode ('9 ')){
M = c-charCode ('0 ');
} Else if (charCode ('A') <= c & c <= charCode ('F ')){
M = c-charCode ('A') + 10;
} Else if (charCode ('A') <= c & c <= charCode ('F ')){
M = c-charCode ('A') + 10;
} Else {
Out [outIndex ++] = charCode ('% ');
Out [outIndex ++] = hexchar;
Out [outIndex ++] = c;
Break;
}
Out [outIndex ++] = 16 * n + m;
Break;
}
}
// TODO support returning arbitrary buffers.
Return out. slice (0, outIndex-1 );
};