Skip to content

Fix minifier silently corrupting/truncating string literals containing URLs, comment-like text, or intentional spacing - #12

Merged
aldanedev-create merged 1 commit into
mainfrom
fix/vel-runtime-and-css
Aug 28, 2026
Merged

Fix minifier silently corrupting/truncating string literals containing URLs, comment-like text, or intentional spacing#12
aldanedev-create merged 1 commit into
mainfrom
fix/vel-runtime-and-css

Conversation

@aldanedev-create

Copy link
Copy Markdown
Owner

See commit message for full details. minify runs by default on every teloce build - confirmed any string literal containing a URL caused catastrophic truncation (unterminated string, SyntaxError), and fake-comment-looking or multi-spaced string content was silently corrupted, in both JS and CSS minification. Fixed with proper string-aware scanning.

…g URLs, comment-like text, or intentional spacing

Started an audit of @teloce/bundler (the pieces not already touched by
an earlier session's fix for empty build output). minifier/index.ts's
JS and CSS minifiers ran plain regexes for comment stripping and
whitespace collapsing directly against raw source, with zero awareness
of string literals - the same class of bug found repeatedly in
@teloce/sfc's parser this session, but here the blast radius is worse:
minification runs by default (minify defaults to on) on every
`teloce build`, so this could silently corrupt any real component.

Confirmed with completely ordinary code, not edge cases:
- `const url = "http://example.com/api"; fetch(url)...` - the `//`
  inside the URL string matched the line-comment regex, deleting
  everything from that point to the end of the line. Since this was
  all one line, the closing quote and the entire rest of the statement
  vanished, leaving `const url = "http:` - an unterminated string
  literal, a straight SyntaxError that fails to even parse. URLs in
  string literals are about as common a pattern as JavaScript has.
- `const s = "a /* fake comment */ b";` - text inside a string that
  merely looks like a block comment got stripped out of the string
  entirely, silently changing its actual content with zero error
  reported.
- `const msg = "Hello   World";` - intentional multiple spaces inside a
  string got collapsed to one, again silently changing what the string
  contains.
- The identical three bugs existed in minifyCSS too: `content: "/* not
  a comment */"` (a real CSS technique) was reduced to an empty string
  entirely, and multi-space CSS string content was silently collapsed
  the same way.

Fixed both minifyJavaScript and minifyCSS by replacing the sequence of
independent regex passes with a single, proper string-and-comment-aware
scan (correctly handling escaped quotes) before any comment removal or
whitespace collapsing happens - string contents are now always emitted
byte-for-byte untouched, matching the same core technique already used
several times this session for @teloce/sfc's parser. The follow-up
punctuation-spacing tightening pass (`{ ` -> `{`, ` }` -> `}`, etc.) was
similarly rewritten to skip over string literals rather than operate on
the whole source blindly.

Verified: the URL case now produces valid, correctly minified,
executable JavaScript with the URL intact (confirmed by actually running
`teloce build` end to end on a real file containing a URL, then
executing the resulting output - previously this exact scenario, with
minification on by default, produced a SyntaxError); the fake-comment
and multi-space string cases are now preserved exactly in both JS and
CSS; real comments are still correctly stripped in both; normal
punctuation-tightening for actual code is unaffected.

Verified: full regression sweep across everything from this session and
previous ones still passes, plus a full "pnpm -r build" across the whole
workspace with zero errors.
@aldanedev-create
aldanedev-create merged commit ee3a1af into main Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant