fix(view/compiler): bail on unterminated strings and invalid numeric literals - #190
Merged
Conversation
…literals
scanStringLiteral returned start+1 unconditionally, never checking the
closing quote was found, so an unterminated literal (e.g. bq-text="'oops")
was copied verbatim and compileExpression reported { ok: true } with a
syntactically broken body. Since emitModule writes every expression into
one module, one bad entry throws at import and takes down every
precompiled expression in the file (no per-expression runtime fallback).
scanStringLiteral now throws Bail on reaching end-of-input without the
matching quote, and scanned numeric runs are validated against a
numeric-literal regex (rejecting e.g. 1ex). Both bails route through the
existing catch to { ok: false }, so the expression falls back to the
runtime evaluator.
Fixes #170
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #170 (Medium; build-breaking).
scanStringLiteralreturnedi + 1unconditionally and never verified the closing quote, so an unterminated literal (<p bq-text="'oops">) was copied verbatim andcompileExpressionreturned{ ok: true }with a broken body. BecauseemitModulewrites every expression into one module, a single malformed entry throws at import time and takes down all precompiled expressions in that file — with no per-expression runtime fallback. Malformed numeric literals (1ex) hit the same class of bug viascanNumericLiteral.Fix
scanStringLiteralthrowsBail('unterminated string literal')when it reaches end-of-input without the matching quote._separators); invalid runs throwBail('invalid numeric literal').Both bails route through the existing
try/catchincompileExpressionto{ ok: false, reason }, so the expression cleanly falls back to the runtime evaluator instead of poisoning the module.Verification
'oops/"unclosed/greeting + 'tailbail; escaped-quote strings still compile;1ex/1e/0xG1bail while1,1.5,0xFF,1e3,1_000,.5,0b1010still compile. Both new tests fail on the pre-fix code.tsc --noEmitclean.🤖 Generated with Claude Code