overlongUTF8

This tag converts all characters below or equal to 0x7ff into overflow UTF-8 sequences

Created by: hackvertor
Installed 1 times

Category: Charsets

Created on: Monday, December 9, 2024 at 12:36:41 PM

Updated on: Wednesday, December 11, 2024 at 1:41:02 PM

This is a built in tag
Tag arguments
[]
Code
class overlongUTF8 {
  encode(input) {
    let result = "";
    for (const char of input) {
      const codePoint = char.codePointAt(0);
      if (codePoint <= 0x7f) {
        result += `%C0%${(0x80 | codePoint).toString(16).toUpperCase()}`;
      } else if (codePoint <= 0x7ff) {
        result += `%E0%80%${(codePoint & 0xff).toString(16).toUpperCase()}`;
      } else {
        result += char;
      }
    }
    return result;
  }
}