mirror of
https://github.com/diced/zipline.git
synced 2026-01-10 12:13:42 -08:00
fix: conditional modifiers fix (#667)
* should be signed
* remove boolean modifiers that cna be replaced by istrue/isfalse
* added exists check on string, removed isfalse check on boolean since it the same as istrue but inverting the true/false strings
* add ::exists conditional modifier to date since {file.deletesAt} can be null
* Fix parser regex
before this fix, here `{file.createdAt::locale::it-IT,Europe/Rome}{file.id}` it would matcg `it-IT,Europe/Rome}{file.id` as locale timezone
here `{file.name::exists["yes"||"no"]}{file.originalName::exists["yes"||"no"]}` it would match `yes"||"no"]}{file.originalName::exists["yes"||"no` as `mod_check_true` group
* Forgot `\` before first `{` in the regex
* add conditional mods to originalName too, fix regex not matching when true/false string had "\n", fix "::exists" matching on string when they were "null"
---------
Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
85699e658c
commit
33522fcdc6
@@ -25,7 +25,6 @@ export type ParseValue = {
|
||||
|
||||
export function parseString(str: string, value: ParseValue) {
|
||||
if (!str) return null;
|
||||
str = str.replace(/\\n/g, '\n');
|
||||
|
||||
const replacer = (key: string, value: unknown) => {
|
||||
if (key === 'password' || key === 'avatar') return '***';
|
||||
@@ -76,7 +75,14 @@ export function parseString(str: string, value: ParseValue) {
|
||||
const decoded = decodeURIComponent(escape(getV[matches.groups.prop as keyof ParseValue['file']]));
|
||||
str = replaceCharsFromString(
|
||||
str,
|
||||
modifier(matches.groups.mod || 'string', decoded),
|
||||
modifier(
|
||||
matches.groups.mod || 'string',
|
||||
decoded,
|
||||
matches.groups.mod_tzlocale ?? undefined,
|
||||
matches.groups.mod_check_true ?? undefined,
|
||||
matches.groups.mod_check_false ?? undefined,
|
||||
value,
|
||||
),
|
||||
index,
|
||||
re.lastIndex,
|
||||
);
|
||||
@@ -114,7 +120,7 @@ export function parseString(str: string, value: ParseValue) {
|
||||
re.lastIndex = index;
|
||||
}
|
||||
|
||||
return str;
|
||||
return str.replace(/\\n/g, '\n');
|
||||
}
|
||||
|
||||
function modifier(
|
||||
@@ -224,12 +230,12 @@ function modifier(
|
||||
return `{unknown_str_modifier(${mod})}`;
|
||||
|
||||
if (_value) {
|
||||
return value
|
||||
return value != 'null' && value
|
||||
? parseString(check_true, _value) || check_true
|
||||
: parseString(check_false, _value) || check_false;
|
||||
}
|
||||
|
||||
return value ? check_true : check_false;
|
||||
return value != 'null' && value ? check_true : check_false;
|
||||
}
|
||||
case mod.startsWith('='): {
|
||||
if (typeof check_true !== 'string' || typeof check_false !== 'string')
|
||||
@@ -416,17 +422,13 @@ function modifier(
|
||||
|
||||
if (
|
||||
typeof check_false == 'string' &&
|
||||
['>', '>=', '=', '<=', '<', '~', '$', '^'].some((modif) => mod.startsWith(modif))
|
||||
(['>', '>=', '=', '<=', '<', '~', '$', '^'].some((modif) => mod.startsWith(modif)) ||
|
||||
['istrue', 'exists'].includes(mod))
|
||||
) {
|
||||
if (_value) return parseString(check_false, _value) || check_false;
|
||||
return check_false;
|
||||
}
|
||||
|
||||
if (typeof check_false == 'string' && ['istrue', 'isfalse', 'exists'].includes(mod)) {
|
||||
if (_value) return parseString(check_false, _value) || check_false;
|
||||
return check_false;
|
||||
}
|
||||
|
||||
return `{unknown_modifier(${mod})}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user