Skip to content

Commit f6cd381

Browse files
Copilothotlong
andcommitted
fix: use ExpressionEvaluator instead of new Function for conditional formatting, extract PREVIEW_ROW_COUNT constant
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent f9ddbee commit f6cd381

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

packages/plugin-grid/src/ImportWizard.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export interface ImportResult {
3434

3535
type WizardStep = 'upload' | 'mapping' | 'preview';
3636

37+
/** Maximum number of rows to show in the preview step */
38+
const PREVIEW_ROW_COUNT = 10;
39+
3740
/** CSV parser with quote handling */
3841
function parseCSV(text: string): string[][] {
3942
const rows: string[][] = [];
@@ -211,7 +214,7 @@ const StepPreview: React.FC<{
211214
Object.entries(mapping).map(([idx, fieldName]) => ({
212215
csvIdx: Number(idx), header: headers[Number(idx)], field: fields.find((f) => f.name === fieldName)!,
213216
})), [mapping, headers, fields]);
214-
const previewRows = rows.slice(0, 10);
217+
const previewRows = rows.slice(0, PREVIEW_ROW_COUNT);
215218

216219
const rowValidations = useMemo(() => previewRows.map((row, rIdx) => {
217220
const errs: Record<number, string> = {};

packages/plugin-list/src/ListView.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { SchemaRenderer, useNavigationOverlay } from '@object-ui/react';
1616
import { useDensityMode } from '@object-ui/react';
1717
import type { ListViewSchema } from '@object-ui/types';
1818
import { usePullToRefresh } from '@object-ui/mobile';
19+
import { ExpressionEvaluator } from '@object-ui/core';
1920

2021
export interface ListViewProps {
2122
schema: ListViewSchema;
@@ -80,13 +81,12 @@ export function evaluateConditionalFormatting(
8081
for (const rule of rules) {
8182
let match = false;
8283

83-
// Expression-based evaluation (L2 feature)
84+
// Expression-based evaluation (L2 feature) using safe ExpressionEvaluator
8485
if (rule.expression) {
8586
try {
86-
const expr = rule.expression.replace(/^\$\{/, '').replace(/\}$/, '');
87-
// Build a safe evaluation context with data fields
88-
const fn = new Function('data', `try { return !!(${expr}); } catch { return false; }`);
89-
match = fn(record) === true;
87+
const evaluator = new ExpressionEvaluator({ data: record });
88+
const result = evaluator.evaluate(rule.expression, { throwOnError: true });
89+
match = result === true;
9090
} catch {
9191
match = false;
9292
}

0 commit comments

Comments
 (0)