feat(operations): add ToFullwidth operation for ASCII to fullwidth conversion

This commit is contained in:
Jyeu 2026-03-14 22:04:40 +08:00
parent d195a51e2e
commit e0498f4b32
2 changed files with 59 additions and 1 deletions

View File

@ -49,6 +49,7 @@
"Escape Unicode Characters", "Escape Unicode Characters",
"Unescape Unicode Characters", "Unescape Unicode Characters",
"Normalise Unicode", "Normalise Unicode",
"To Fullwidth",
"To Quoted Printable", "To Quoted Printable",
"From Quoted Printable", "From Quoted Printable",
"To Punycode", "To Punycode",
@ -591,4 +592,4 @@
"Comment" "Comment"
] ]
} }
] ]

View File

@ -0,0 +1,57 @@
/**
* @author jyeu [chen@jyeu.xyz]
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
/**
* To Fullwidth operation
*/
class ToFullwidth extends Operation {
/**
* ToFullwidth constructor
*/
constructor() {
super();
this.name = "To Fullwidth";
this.module = "Encodings";
this.description =
"Converts ASCII (halfwidth) characters to their fullwidth Unicode equivalents (U+FF01U+FF5E). Commonly used in security testing to bypass WAF keyword filters, evade regex-based blocklists, and exploit Unicode normalization (NFKC/NFKD) vulnerabilities in web applications and path parsers. For example, <code>/dmin</code> may bypass a WAF rule matching <code>/admin</code> if the backend normalises Unicode before routing.";
this.infoURL =
"https://wikipedia.org/wiki/Halfwidth_and_fullwidth_forms_(Unicode_block)";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {never} _args
* @returns {string}
*/
run(input, _args) {
let output = "";
for (const char of input) {
const code = char.codePointAt(0);
if (code === 0x20) {
// Regular space -> Ideographic space (U+3000)
output += "\u3000";
} else if (code >= 0x21 && code <= 0x7e) {
// Visible ASCII characters -> Fullwidth equivalents (U+FF01U+FF5E)
output += String.fromCodePoint(code + 0xfee0);
} else {
// Non-ASCII characters (CJK, newlines, etc.) are passed through unchanged
output += char;
}
}
return output;
}
}
export default ToFullwidth;