Fixed in browser match_str to closely match yt-dlp match_str
This commit is contained in:
parent
6f059c78b8
commit
4a017500c7
2 changed files with 35 additions and 13 deletions
|
|
@ -290,7 +290,7 @@ const run_test = async (): Promise<void> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
test_data.value.in_progress = true
|
test_data.value.in_progress = true
|
||||||
test_data.value.data.status = null
|
test_data.value.data.status = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await request('/api/conditions/test', {
|
const response = await request('/api/conditions/test', {
|
||||||
|
|
@ -361,7 +361,7 @@ const show_data = (): string => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const logic_test = computed(() => {
|
const logic_test = computed(() => {
|
||||||
if (!test_data.value.data || !test_data.value.data.data) {
|
if (Object.keys(test_data.value.data?.data ?? {}).length < 1) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,28 @@ function match_str(filterStr: string, dct: Record<string, any>, incomplete: bool
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filterStr
|
if (/\s*&\s*$/.test(filterStr)) {
|
||||||
.split(/(?<!\\)&/)
|
return false;
|
||||||
.every(filterPart => _match_one(filterPart.replace(/\\&/g, '&'), dct, incomplete));
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const filterParts = filterStr
|
||||||
|
.split(/(?:(^|[^\\]))&/g)
|
||||||
|
.reduce((parts, part, index, array) => {
|
||||||
|
if (index % 2 === 0) {
|
||||||
|
parts.push((part + (array[index + 1] || '')).replace(/\\&/g, '&'));
|
||||||
|
}
|
||||||
|
return parts;
|
||||||
|
}, [] as string[]);
|
||||||
|
|
||||||
|
if (filterParts.some(fp => !fp.trim())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filterParts.every(filterPart => _match_one(filterPart, dct, incomplete));
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function lookup_unit_table(unitTable: Record<string, number>, s: string, strict = false): number | null {
|
function lookup_unit_table(unitTable: Record<string, number>, s: string, strict = false): number | null {
|
||||||
|
|
@ -101,7 +120,14 @@ function _match_one(filterPart: string, dct: Record<string, any>, incomplete: bo
|
||||||
const opFn = negation ? (a: any, b: any) => !unnegatedOp(a, b) : unnegatedOp;
|
const opFn = negation ? (a: any, b: any) => !unnegatedOp(a, b) : unnegatedOp;
|
||||||
|
|
||||||
let value = quoted ?? plain ?? '';
|
let value = quoted ?? plain ?? '';
|
||||||
if (quote) value = value.replace(new RegExp(`\\\\${quote}`, 'g'), quote);
|
|
||||||
|
if (quote) {
|
||||||
|
value = value.replace(new RegExp(`\\\\${quote}`, 'g'), quote);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(key! in dct)) {
|
||||||
|
return isIncomplete(key!) || Boolean(noneInclusive);
|
||||||
|
}
|
||||||
|
|
||||||
const actual = dct[key!];
|
const actual = dct[key!];
|
||||||
let numeric: number | null = null;
|
let numeric: number | null = null;
|
||||||
|
|
@ -117,10 +143,6 @@ function _match_one(filterPart: string, dct: Record<string, any>, incomplete: bo
|
||||||
throw new Error(`Operator ${op} only supports string values!`);
|
throw new Error(`Operator ${op} only supports string values!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actual == null) {
|
|
||||||
return isIncomplete(key!) || Boolean(noneInclusive);
|
|
||||||
}
|
|
||||||
|
|
||||||
return opFn(actual, numeric !== null ? numeric : value);
|
return opFn(actual, numeric !== null ? numeric : value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,12 +155,12 @@ function _match_one(filterPart: string, dct: Record<string, any>, incomplete: bo
|
||||||
const mu = filterPart.trim().match(unaryRe);
|
const mu = filterPart.trim().match(unaryRe);
|
||||||
if (mu?.groups) {
|
if (mu?.groups) {
|
||||||
const { op, key } = mu.groups;
|
const { op, key } = mu.groups;
|
||||||
const actual = dct[key!];
|
|
||||||
|
|
||||||
if (actual === undefined && isIncomplete(key!)) {
|
if (!(key! in dct)) {
|
||||||
return true;
|
return isIncomplete(key!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const actual = dct[key!];
|
||||||
const unaryOp = UNARY_OPERATORS[op!];
|
const unaryOp = UNARY_OPERATORS[op!];
|
||||||
|
|
||||||
if (!unaryOp) {
|
if (!unaryOp) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue