import { swapKeyValPairs } from "./4-swap-key-val-pairs"; const forwardXml = { "<": "<", ">": ">", "&": "&", """: "\"", "'": "\'", "%0d": "\r", "%0a": "\n", }; const reverseXml = swapKeyValPairs(forwardXml); const reForwardXml = /(<|>|&|"|'|%0d|%0a)/g; const reReverseXml = /[<>&"'\r\n]/g; export function xmlRestore(s: string): string { //C:\Y\c\dp\pm\Components\Include\atl\atl_strings.h::xml_remove() return s ? s.replace(reForwardXml, (m) => forwardXml[m as keyof typeof forwardXml]) : ''; } export function xmlEscape(s: string): string { return s ? s.replace(reReverseXml, (m) => reverseXml[m]) : ''; } // Persent encoding export function persentRemove(s: string): string { // decodeURI will fail on: <input name="Sign in name" tabindex="1" id="signInName" type="email" placeholder="Email Address" pattern="^[a-zA-Z0-9.!#$%&amp;’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$" value=""> try { return decodeURI(s); //TODO: decodeURI does not do all % encodings //TODO: decodeURI will not work on URL params } catch (error) { return s; } }