fix: escape manufacturerPartNumber safely in generated TSX (closes #552) - #553
Open
tcsenpai wants to merge 1 commit into
Open
fix: escape manufacturerPartNumber safely in generated TSX (closes #552)#553tcsenpai wants to merge 1 commit into
tcsenpai wants to merge 1 commit into
Conversation
…circuit#552) manufacturerPartNumber was interpolated directly into a plain double-quoted JSX attribute for every generated component type. JSX quoted attributes do not interpret JavaScript escape sequences, so a manufacturer part number containing a double quote produced an unterminated string literal and invalid TSX. Added a renderJsxStringAttr helper that keeps the existing plain attr="value" form when the value is safe, and falls back to a JSX expression container with JSON.stringify escaping otherwise. This keeps existing snapshots stable for ordinary part numbers while fixing the escaping for part numbers containing quotes, backslashes, or braces. Added a regression test that fails on main and passes with the fix.
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.
Fixes #552.
generateTypescriptComponentinterpolatedmanufacturerPartNumberdirectly into a plain double-quoted JSX attribute for every generated component type (chip, diode, led, pushbutton, switch, capacitor, resistor, inductor, crystal, connector). JSX quoted attributes do not interpret JavaScript escape sequences, so a manufacturer part number containing a double quote produced an unterminated string literal, making the generated TSX fail to parse.Fix
Added a small
renderJsxStringAttrhelper ingenerate-typescript-component.ts:",\,{, or}, it keeps the existing plainattr="value"form, so output for ordinary part numbers is unchanged and all existing inline snapshots stay green.JSON.stringifyescaping, matching the convention already used elsewhere in this file forsupplierPartNumbersand pin labels.Testing
Added
tests/convert-to-ts/manufacturer-part-number-quote.test.ts, which mutates an existing fixture's manufacturer part number to include a double quote, converts it to TSX, and asserts the result parses without syntax errors using the TypeScript compiler's source-file parser. Confirmed this test fails on main and passes with the fix.Before pushing:
bun run formatbun run format:checkbunx tsc --noEmitbun test(225 pass, 0 fail)This report and fix were prepared with AI assistance.