openpencil/tests/engine
Danila Poyarkov 99925e4c25
fix(tools): evaluate calc expressions without expr-eval (#753)
* fix(tools): evaluate calc expressions without expr-eval

expr-eval has an unpatched critical advisory for code execution through
toJSFunction(), which compiles expressions with new Function
(GHSA-q9v2-7m5w-4693). The advisory covers every published version, so
`bun run check:audit` fails on every branch and `bun audit fix` has nothing
to upgrade to. The calc tool only ever called evaluate(), so the advisory's
own vector was not reachable, but the dependency stays flagged and the
evaluator's surface was far wider than the tool documents: random(), factorials,
trigonometry, constants, strings, array indexing, property access and
statement sequences all evaluated, while the documented ** operator did not
parse at all, since expr-eval spells power as ^.

Replace it with a recursive-descent evaluator for exactly the documented
grammar. It compiles nothing, reaches no host object, and fixes **, which is
right-associative and binds tighter than a leading sign, so -2 ** 2 is -4 as
in ordinary notation. Non-finite results are still reported by the tool rather
than the evaluator, so 1 / 0 keeps its "Produced Infinity" message.

The tool had no tests; both the evaluator and the tool's JSON-array and
error-reporting paths are covered now.

* refactor(tools): parse calc expressions with jsep

Replace the hand-written tokenizer and recursive-descent parser with jsep,
a maintained zero-dependency expression parser with no advisory history, and
keep only the tree walk: an allowlist of node types, arithmetic operators and
the documented functions. Parsing, where the vulnerabilities in this class of
library live, is no longer ours to maintain.

Behaviour follows the parser rather than the previous hand-written precedence,
so a leading sign now binds tighter than '**' and '-2 ** 2' is 4; the tests
pin that alongside right-associativity. Parse errors keep jsep's own wording
and character positions.

* fix(tools): reject inherited names and fold long calc argument lists

Two findings from review of this branch. The function lookup used `in`, so
an inherited key such as `constructor(1)` passed the guard and then failed
while destructuring a missing arity, reporting a TypeError instead of an
unknown function; it now uses Object.hasOwn. min and max spread their
arguments, which overflows the call stack on V8 at roughly 125k arguments,
so they fold instead. Both paths are covered by tests.
2026-09-25 01:44:46 +04:00
..
acp
app feat: open documents and layers from openpencil:// and web links (#708) 2026-09-18 14:45:49 +03:00
bytes refactor(core): centralize Base64 encoding 2026-07-28 08:27:22 +03:00
cli ci: shard unit tests by owner and cut the quick suite from 100 s to 13 s (#715) 2026-09-17 10:18:16 +03:00
clipboard ci: shard unit tests by owner and cut the quick suite from 100 s to 13 s (#715) 2026-09-17 10:18:16 +03:00
collab Release v0.15.0 2026-09-16 17:57:35 +03:00
color fix(core): store picker colours in the document's colour profile (#724) 2026-09-18 13:08:49 +03:00
core refactor(canvas): share bounded resource cache bookkeeping 2026-09-15 21:28:16 +03:00
dom-css fix(fig): restore strict parse validation 2026-07-18 03:58:18 +03:00
editor fix: convert document colour profiles, keep text edits live, and fix .fig exports (#716) 2026-09-18 00:43:10 +03:00
figma/api Merge master into fix/create-component-drops-bound-variables 2026-09-02 01:09:01 +03:00
geometry feat(editor): checkpoint live interaction improvements 2026-09-15 11:36:17 +03:00
hit-test perf(scene-graph): accelerate axis-aligned hit tests (#534) 2026-08-16 15:43:25 +03:00
icons fix(core): preserve inline SVG primitives (#485) 2026-08-12 16:02:45 +03:00
io fix: convert document colour profiles, keep text edits live, and fix .fig exports (#716) 2026-09-18 00:43:10 +03:00
kiwi fix(fig): preserve regenerated override lineage 2026-07-21 01:51:27 +03:00
layout test: fix heavy unit-test measurement and round-trip checks (#655) 2026-09-07 00:33:12 +03:00
library build: upgrade oxfmt and format Vue imports (#669) 2026-09-10 02:45:13 +03:00
lint
mcp fix(MCP): add read-only file lifecycle tools (#722) 2026-09-18 11:55:06 +03:00
pen fix(pen): honor layout and sizing defaults (#652) 2026-09-10 17:02:56 +03:00
profiler chore: format codebase 2026-05-24 12:15:29 +03:00
random
render ci: shard unit tests by owner and cut the quick suite from 100 s to 13 s (#715) 2026-09-17 10:18:16 +03:00
scene-graph ci: shard unit tests by owner and cut the quick suite from 100 s to 13 s (#715) 2026-09-17 10:18:16 +03:00
snap
tauri feat(settings): configure tool access, MCP failures, and step limits 2026-09-17 23:55:58 +03:00
text fix(text): preserve cached font coverage and source offsets 2026-09-02 09:26:59 +03:00
tools fix(tools): evaluate calc expressions without expr-eval (#753) 2026-09-25 01:44:46 +04:00
vector feat(canvas): render arrow stroke caps on lines and open vectors 2026-08-31 21:25:38 +03:00
vue fix: convert document colour profiles, keep text edits live, and fix .fig exports (#716) 2026-09-18 00:43:10 +03:00
perf.bench.ts feat: split SceneGraph and Pen packages 2026-06-30 10:54:32 +03:00