From d8949fddc746554fc3bab4a23855a2b9502a9faa Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 2 Jun 2024 15:02:54 +0300 Subject: [PATCH] Escape commas in comma-separated random and pick --- public/scripts/macros.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/scripts/macros.js b/public/scripts/macros.js index 11051d80e..2b4ea17a7 100644 --- a/public/scripts/macros.js +++ b/public/scripts/macros.js @@ -197,7 +197,8 @@ function randomReplace(input, emptyListPlaceholder = '') { // Split on either double colons or comma. If comma is the separator, we are also trimming all items. const list = listString.includes('::') ? listString.split('::') - : listString.split(',').map(item => item.trim()); + // Replaced escaped commas with a placeholder to avoid splitting on them + : listString.replace(/\\,/g, '##�COMMA�##').split(',').map(item => item.trim().replace(/##�COMMA�##/g, ',')); if (list.length === 0) { return emptyListPlaceholder; @@ -221,7 +222,8 @@ function pickReplace(input, rawContent, emptyListPlaceholder = '') { // Split on either double colons or comma. If comma is the separator, we are also trimming all items. const list = listString.includes('::') ? listString.split('::') - : listString.split(',').map(item => item.trim()); + // Replaced escaped commas with a placeholder to avoid splitting on them + : listString.replace(/\\,/g, '##�COMMA�##').split(',').map(item => item.trim().replace(/##�COMMA�##/g, ',')); if (list.length === 0) { return emptyListPlaceholder;