Escape commas in comma-separated random and pick

This commit is contained in:
Cohee 2024-06-02 15:02:54 +03:00
parent 65cf9c8f4d
commit d8949fddc7

View File

@ -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, '##<23>COMMA<4D>##').split(',').map(item => item.trim().replace(/##<23>COMMA<4D>##/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, '##<23>COMMA<4D>##').split(',').map(item => item.trim().replace(/##<23>COMMA<4D>##/g, ','));
if (list.length === 0) {
return emptyListPlaceholder;