From f2f3967d086eb6b29eddd5c8f50f7b7f44cea690 Mon Sep 17 00:00:00 2001 From: Nick Harrison <42382362+nickpharrison@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:09:28 +0000 Subject: [PATCH] Fixes for protection string when there are empty attributes --- src/prettify.js | 2 +- src/utils.js | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/prettify.js b/src/prettify.js index 3cfb488..82368b1 100644 --- a/src/prettify.js +++ b/src/prettify.js @@ -159,7 +159,7 @@ export const prettify = (html, config) => { const ignore = validated_config.ignore.length > 0 trim = validated_config.trim - const protectionString = config?.protection_string || '_&i-£___£%_'; + const protectionString = config?.protection_string || '_!i-£___£%_'; /* Protect ignored elements. */ if (ignore) { diff --git a/src/utils.js b/src/utils.js index b1f6473..11d38ce 100644 --- a/src/utils.js +++ b/src/utils.js @@ -88,11 +88,11 @@ export const ignoreElement = (html, ignore, mode, protectionString) => { const protectElement = (match, capture, protectionString) => { return match.replace(capture, (match) => { return match - .replace(//g, protectionString + 'gt') - .replace(/\n/g, protectionString + 'nl') - .replace(/\r/g, protectionString + 'cr') - .replace(/\s/g, protectionString + 'ws') + .replace(//g, '-' + protectionString + 'gt-') + .replace(/\n/g, '-' + protectionString + 'nl-') + .replace(/\r/g, '-' + protectionString + 'cr-') + .replace(/\s/g, '-' + protectionString + 'ws-') }) } @@ -128,11 +128,11 @@ export const trimify = (html, trim) => { const unprotectElement = (match, capture, protectionString) => { return match.replace(capture, (match) => { return match - .replace(new RegExp(protectionString + 'lt', "g"), '<') - .replace(new RegExp(protectionString + 'gt', "g"), '>') - .replace(new RegExp(protectionString + 'nl', "g"), '\n') - .replace(new RegExp(protectionString + 'cr', "g"), '\r') - .replace(new RegExp(protectionString + 'ws', "g"), ' ') + .replace(new RegExp('-' + protectionString + 'lt-', "g"), '<') + .replace(new RegExp('-' + protectionString + 'gt-', "g"), '>') + .replace(new RegExp('-' + protectionString + 'nl-', "g"), '\n') + .replace(new RegExp('-' + protectionString + 'cr-', "g"), '\r') + .replace(new RegExp('-' + protectionString + 'ws-', "g"), ' ') }) }