Skip to content

fix(tia): end the SFC script tag after quoted attributes that hold > - #2063

Open
benddailey wants to merge 1 commit into
pestphp:5.xfrom
benddailey:fix/tia-sfc-script-attribute-gt
Open

benddailey wants to merge 1 commit into
pestphp:5.xfrom
benddailey:fix/tia-sfc-script-attribute-gt

Conversation

@benddailey

Copy link
Copy Markdown

What:

  • Bug Fix
  • New Feature

Description:

SCRIPT_BLOCK_RE ended the opening <script> tag at the first >, also inside a quoted attribute. A Vue generic component (generic="T extends Record<string, unknown>") then leaked the rest of the tag into the script code, and rolldown failed the whole graph build with [PARSE_ERROR] Unterminated string.

The attribute part of the regex now skips quoted values:

const SCRIPT_BLOCK_RE = /<script\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/script>/gi

Group 1 is still the attribute string, so the lang detection does not change. The three branches cannot match the same character, so the regex stays linear: a 50 kB attribute takes under 1 ms.

Tests in tests/Unit/Plugins/Tia/ViteDepsHelper.php:

  • New tiaSfcFixtures() cases: generic-attribute, generic-attribute-single-quoted, and generic-attribute-before-lang (lang after an attribute that holds >). The existing data-driven tests run on them.
  • A new test checks that the extracted code starts after the opening tag for these cases.
  • A new end-to-end test bundles a generic component through rolldown. Like the existing bundle test, it skips when rolldown is not resolvable.

Related:

Closes #2062

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.

[Bug]: TIA graph build fails on a Vue generic component (">" inside a script tag attribute)

1 participant