malformedUrl

This tag emulates a defective encoder found on a web site.

Created by: hackvertor
Installed 1 times

Category: Convert

Created on: Thursday, January 30, 2025 at 9:46:05 AM

Updated on: Thursday, January 30, 2025 at 12:33:41 PM

This is a built in tag
Tag arguments
[]
Code
class malformedUrl {
  encode(input) {
    return input
      .split("")
      .map((c) => {
        const hex = c.codePointAt(0).toString(16).padStart(2, "0");
        return (
          "%" + hex.substr(0, 1) + this.findMalformedChar(hex.substr(1, 1))
        );
      })
      .join("");
  }

  decode(input) {
    return input.replace(/%(..)/gi, function ($0, c) {
      return String.fromCodePoint(
        parseInt(
          (c.charAt(0).codePointAt(0) % 0x10).toString(16) +
            (c.charAt(1).codePointAt(0) % 0x10).toString(16),
          16,
        ),
      );
    });
  }

  findMalformedChar(hex) {
    for (let i = 0x20; i < 0xff; i++) {
      if ((i % 0x10).toString(16) === hex) return String.fromCodePoint(i);
    }
  }
}