mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2936] [Issue]: Regex Script editor: Live Test preview lies, unsafe patterns slip past the editor, and import stops on the first bad script #1512
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1512
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2936
Originally assigned to: @SpicyMarinara on GitHub.
The regex-script editor's Live Test preview doesn't match what the chat actually does, and several validation gaps let bad scripts get saved or imported with confusing or silent failures. Each item below is independently reproducible in v2.0.6.
A. Live Test preview ignores most of the script's settings
What's wrong: The "Live Test" box shows the transform happening even when, at runtime, the script would never touch that text — because Live Test ignores Apply To (placement), Prompt Only, Specific Characters, and the Depth Range.
How to reproduce (try it yourself):
hello, Replace Withgoodbye.hello world.goodbye world.Where it is:
RegexScriptEditor.tsx— thetestResultmemo (around lines 242–260). Its dependency list is[testInput, localFindRegex, localReplaceString, localFlags, localTrimStrings, regexError]— it never reads placement, promptOnly, target characters, or depth.What's happening: The preview only ever runs find/replace + trim. The real engines gate on all the other fields (
regex-application.ts:94-108,use-apply-regex.ts:69-101), so the preview can show a result a real run would skip.Suggested fix: Have Live Test reflect the gating fields — at minimum show a "won't apply here" notice when the current placement/depth/scope would exclude the sample, or add a placement/depth selector to the test panel.
B. Editor lets you save (and live-test) patterns the server rejects as unsafe
What's wrong: If you type a ReDoS-prone pattern, the editor shows no error and the Save button stays enabled — but clicking Save returns a 400. Worse, the Live Test runs that same pattern synchronously, so a pathological pattern can hang the tab.
How to reproduce (try it yourself):
(a+)+$.as ending inX(e.g.aaaaaaaaaaaaaaaaaaaaaaaaaaX) into Live Test with that pattern.Where it is:
RegexScriptEditor.tsx— theregexErrormemo (~229–239) is a syntax-onlynew RegExp(...)check; Save is disabled only onregexError || characterScopeError(line 439). The editor never imports or callsisPatternSafe. Live Test compiles + runs the pattern inline in thetestResultmemo (~249–250).What's happening:
(a+)+$is syntactically valid, soregexErroris null and Save is enabled. The server schema rejects it viaisPatternSafe(regex.schema.ts:15-21;regex-safety.tsmaxStarHeight=1, so nested-quantifier group height 2 fails). The editor has no equivalent client-side guard.Suggested fix: Run
isPatternSafe(already in@marinara-engine/shared) in the editor: surface it as the same inline error as a syntax error, disable Save when unsafe, and skip running unsafe patterns in Live Test.C. Save failures show a generic "Save failed" / "Validation Error" instead of the real reason
What's wrong: When a save is rejected, the red banner just says "Validation Error" — it doesn't tell the user which field failed or why (e.g. that the pattern is unsafe).
How to reproduce (try it yourself):
(a+)+$(see B).Where it is:
RegexScriptEditor.tsx:307setssaveError = err.message.api-client.ts:141constructsApiError(status, body.error ?? statusText, body), somessageis"Validation Error"(error-handler.ts:10-16). The actionable per-field text lives inerror.payload.details[].message, which the editor never reads.What's happening: The server returns
{ error: "Validation Error", details: [{ path, message }] }. The client surfaces only the top-levelerrorstring.Suggested fix: When the caught error is an
ApiErrorwithpayload.details, join thepath: messageentries into the banner text.D. A stored unsafe script becomes uneditable — every save 400s, even renaming it
What's wrong: If a script with an unsafe pattern already exists in storage, you can't edit it at all through the editor: any Save (even just changing the name) is rejected, because the editor always resubmits the unsafe
findRegex.How to reproduce (try it yourself): This needs an unsafe pattern already in the DB (e.g. via a
.maridbrestore or raw DB insert — it can't be created through the editor because of B). Then open that script, change only its Name, and Save → 400.Where it is:
RegexScriptEditor.tsx:278-291always includesfindRegexin the PATCH payload. The route parsesupdateRegexScriptSchema(regex-scripts.routes.ts:32), which iscreateRegexScriptSchema.partial()(regex.schema.ts:33)..partial()only makes fields optional — it keeps the.refineonfindRegexwhenever it's present, so the unsafe pattern is re-validated and rejected on every save.What's happening: The row-level enable toggle escapes this because it sends only
{ id, enabled }(CharacterRegexSection.tsx:318) — confirming it's the editor's blanket resubmission offindRegexthat triggers the rejection.Suggested fix: Tie this to fix B (block creating unsafe patterns up front) and/or only send changed fields on update so an untouched
findRegexisn't re-validated, or surface the validation reason (fix C) so the user knows the pattern must change.E. Importing a batch of regex scripts stops at the first rejected one
What's wrong: When you import a file with several regex scripts and one of them is rejected by the server, the import aborts there: scripts before it are created, the failing one and everything after it are not, and you get only a generic error.
How to reproduce (try it yourself):
findRegex: "(.*)+"(unsafe).Where it is:
CharacterRegexSection.tsx:193-205andPresetsPanel.tsx:407-418both loopawait createRegex.mutateAsync(...)inside a single try/catch. A thrown rejection breaks out of the loop and only sets a genericimportError.Suggested fix: Wrap each
mutateAsyncin its own try/catch, collect per-entry failures, continue the loop, and report "imported N, skipped M (reasons…)".F. Live Test ignores the typographic-quotes setting that the chat applies
What's wrong: With the quote-format setting set to typographic, the Live Test preview still shows straight quotes while the actual rendered chat message shows curly ones. (No divergence at the default "straight" setting, so this is low-impact.)
How to reproduce (try it yourself):
He said "hi"."hi"straight; the rendered chat message shows curly quotes.Where it is: The display path wraps its output in
formatTextQuotes(..., quoteFormat)(use-apply-regex.ts:148,156); the editor'stestResultmemo does not and never importsformatTextQuotes. DefaultquoteFormatis"straight"(ui.store.ts:1193), so this only diverges once it's set to typographic.Suggested fix: Apply
formatTextQuotes(result, quoteFormat)to the Live Test output to match the display path.G. Invalid regex flags (e.g.
gg) save fine but silently make the whole script do nothingWhat's wrong: The
flagsfield isn't validated. A script with bad flags (like a duplicatedgg) saves and imports without complaint, but at runtime it silently never matches anything — the regex constructor throws and the error is swallowed.How to reproduce (try it yourself):
"flags": "gg"and import it (or otherwise getgginto the flags).Where it is:
regex.schema.ts:25—flags: z.string().default("gi")with no constraint. Import copiesentry.flagsverbatim (CharacterRegexSection.tsx:81, andPresetsPanelvia the samenormalizeRegexImportEntry). At runtimenew RegExp(findRegex, flags)throws "Invalid flags…" and is swallowed by the try/catch inregex-application.ts:116-127anduse-apply-regex.ts:103-117. The editor's flag buttons only offerg/i/m/s/u(line 570), so this only arrives via import/hand-edit.Suggested fix: Constrain
flagsin the schema to/^[gimsuy]*$/with no duplicates (Zod.refine), so invalid flags are rejected at save/import instead of silently no-opping the script.AI-investigated against v2.0.6; verify the reproduction before fixing.
@SpicyMarinara commented on GitHub (Jun 28, 2026):
Addressed in the staging fixes: the regex editor now runs the shared safety check before preview/save, shows validation detail messages, applies quote formatting in Live Test, allows other fields on an unchanged unsafe stored pattern to be saved, validates flags/depth ranges, and import flows now continue past bad entries with visible skip reasons.
@kolacheee commented on GitHub (Jun 28, 2026):
Re-verified this against v2.0.6 (read the code + reproduced each part) and rewrote the description in plain language with concrete, try-it-yourself reproduction steps. Any original claims I could not actually reproduce were dropped (and called out at the end where relevant). Should be much easier to follow and confirm now — sorry the first version was so dense.