Repository navigation
fix(scripting): CRLF bug replace decomment with jsonc-parser - #9602
abhishekp-bruno wants to merge 8 commits into
Conversation
…decomment Comments in JSON request bodies and GraphQL variables were stripped with `decomment`, which tokenises the text with esprima 4 to locate regex literals. Esprima 4 has not kept up with the language, so a body containing a numeric separator such as `1_000` threw before the request was sent. `decomment` also picks a single line ending for the whole text by majority vote, which is wrong for any input that mixes CRLF and LF. `jsonc-parser` is the comment-aware JSON scanner VS Code uses. It is already a dependency of bruno-app, has no dependencies of its own, scans only JSON tokens so no JavaScript syntax can trip it, and produces byte-identical output to `decomment` on every body shape the existing specs cover. - Swap the JSON body and GraphQL variable sites in the app and the CLI to `stripComments` from `jsonc-parser`. - Declare `jsonc-parser` in both manifests; it previously resolved only by hoisting. - Add body specs for CRLF input, a trailing comment on a single line, `//` inside a string value, and a numeric separator. `decomment` stays declared for now because the script runtimes on main still import it; that removal lands with fix/decomment-crlf-bug, after which the dependency can be dropped.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe CLI and Electron packages replace ChangesComment handling and script execution
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to
|
Scripts never needed comment stripping: QuickJS and the Node VM ignore comments natively, and every wrapper puts a newline before its closing brace. Running `decomment` over the merged script was also the cause of the `expecting ')'` failure on mixed CRLF/LF input, since it picks one line ending for the whole text by majority vote. - Pass pre-request, post-response, test and gRPC hook scripts straight to the runtime in both the app and the CLI. - Remove `decomment` from both manifests and the lockfile. Its only dependency, esprima 4, remains solely as dev-time tooling under bruno-app. This overlaps with fix/decomment-crlf-bug on the three script files; the edits are identical, so whichever lands second rebases cleanly.
…rom the bug report
47711f3 to
0d14809
Compare
| return ''; | ||
| } | ||
|
|
||
| // wrapAndJoinScripts counts lines by splitting on \n, so every segment must be LF. |
| }); | ||
|
|
||
| describe('CLI wrapAndJoinScripts: CR-only line endings', () => { | ||
| test('counts lines of a CR-only collection script so the request segment maps to the right lines', () => { |
There was a problem hiding this comment.
Add CRLF, LF cases too like
CRLF -> LF
LF -> LF unchnaged
| await expect(runtime.runRequestScript(merge('// Set the pet ID before sending the request'), {}, {}, {}, '.', onConsoleLog, process.env)).resolves.toBeDefined(); | ||
| }); | ||
|
|
||
| it('runs the same scripts in the Node VM', async () => { |
There was a problem hiding this comment.
Why don't we have the ['quickjs', 'nodevm'] here too? Also I guess we don't have to test post-response and tests, i guess, we just need to make sure that the scripts is running without crashing! Running prerequestscript is more than enough in that case
|
@abhishekp-bruno I do not see any converter changes! aren't we supposed to do the normalization for postman imports too? |
|
@abhishekp-bruno can we check how the error formatter works, I guess it may also need some normalization, so that we can accurately point to the exact line from which the error is thrown, |
|
@abhishekp-bruno we will have to be careful replacing |
|
Since |
BRU-4710
Description
A valid // comment in a request's pre-request script can make the script fail with SyntaxError: expecting ')', even though the JavaScript is valid. Removing the comment, or changing it to a /* */ block comment, makes the request run normally.
Problem
in certain conditions when we have CRLF and LF endings in a merged script, decomment library would fail to parse it at the line where a line had CRLF and next line would have LF or vice versa and return whatever it parsed till that point.
we wrap our scripts in a async wrapper and this incomplete parser would miss the closing
})(...)causing the script to fail while executingFix
with the wrapper in place we do not need decomment anymore in the scripting part of our app.
it is needed in the JSON body of the request.
we replace the decomment library with the jsonc-parcer since the decomment library is not maintained anymore and causes the parser to fail on any new JS features introduced after 2018 since it is internally dependant on esprima 4 which is outdated now.
Screenshots
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit