fix(prompt-files): avoid crash when <system> tag is unclosed#12519
Open
Pluviobyte wants to merge 1 commit into
Open
fix(prompt-files): avoid crash when <system> tag is unclosed#12519Pluviobyte wants to merge 1 commit into
Pluviobyte wants to merge 1 commit into
Conversation
parsePromptFile only checked for an opening `<system>` tag before running
`prompt.split("</system>")[1].trim()`. A `.prompt` file that contains
`<system>` but omits the closing `</system>` makes that split return a
single-element array, so `[1]` is undefined and `.trim()` throws
`TypeError: Cannot read properties of undefined (reading 'trim')`,
failing config load over a simple authoring typo.
Require both tags before parsing the system block; an unclosed tag now
falls through and the whole body is treated as the prompt. Adds tests for
the closed, unclosed, and no-system cases.
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Description
parsePromptFileonly checks for an opening<system>tag before splitting on the closing one:If a
.promptfile contains<system>but omits the closing</system>(an easy authoring typo),prompt.split("</system>")returns a single-element array, so[1]isundefinedand.trim()throws:Because
.promptfiles are parsed during config / slash-command load, one malformed file breaks loading instead of degrading gracefully.Fix
Require both
<system>and</system>before parsing the system block. An unclosed tag now falls through and the entire body is treated as the prompt (no crash).Checklist
Screen recording or screenshot
N/A — parser crash fix; covered by the new tests.
Tests
Added
core/promptFiles/parsePromptFile.vitest.tscovering:<system>…</system>block (parsed correctly)<system>tag (no longer throws; whole body kept as the prompt)Verified the unclosed case fails on the old code with
Cannot read properties of undefined (reading 'trim')and passes with the fix.tsc -p ./ --noEmitreports 0 errors andprettier --checkpasses locally.Made with Cursor
Summary by cubic
Fix prevents a crash when a .prompt file includes without a closing . The parser now only extracts a system message if both tags are present; otherwise it treats the content as the prompt.
Written for commit 84c0f34. Summary will update on new commits.
Review in cubic