Conversation
Co-Authored-By: OpenAI Codex <codex@openai.com>
…ction Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
|
@timfish could u re-approve the CI run? I fixed the test failures (hopefully the last ones). I'd test it out properly locally... but I'm facing a stupid issue of this project having such a big dep graph that I'm currently running out of disk space 🫠 I need to clean it up but didn't have time for that right now. FWIW, I was totally testing this... but through proxy isolated pnpm-based projects. So I, from the start, tested he behavioral changes of this PR - but then I faced some outdated snapshots here 😢 |
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
|
I had to sync this with develop given the merge conflicts, this this will require now a CI re-run. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5f98e4c. Configure here.
Co-Authored-By: OpenAI Codex <codex@openai.com>
d23cafb to
fc910dc
Compare
Co-Authored-By: OpenAI Codex <codex@openai.com>
fc910dc to
a711a31
Compare
|
Thanks, will review this week! |
timfish
left a comment
There was a problem hiding this comment.
Thanks, the scanner and the move to processAssets both look right to me. A few follow-ups inline, plus one that has no diff line to hang on: COMMENT_USE_STRICT_REGEX in packages/bundler-plugins/src/core/index.ts has no users left after this change. Can you delete it (and its CodeQL note)?
| const quote = code[start]; | ||
| if (quote !== '"' && quote !== "'") { | ||
| return undefined; | ||
| } |
There was a problem hiding this comment.
We already have a scanner for this in packages/nextjs/src/config/loaders/valueInjectionLoader.ts (findInjectionIndexAfterDirectives), and @sentry/nextjs already imports from @sentry/bundler-plugins/core. Could you export this one from core and switch the Next.js loaders to it, so the edge cases you fixed here (CR-only, U+2028/9, ++/--, in/instanceof) apply there too? Happy for that to be a follow-up PR if you'd rather keep this one focused.
| const comment = code.slice(position, commentEnd + 2); | ||
| hasLineBreak ||= /[\n\r\u2028\u2029]/.test(comment); | ||
| position = commentEnd + 2; | ||
| } else { |
There was a problem hiding this comment.
Nit: this copies the whole remainder of the chunk to test at most a dozen characters. A bounded slice (position + 'instanceof'.length + 1) gives the same result.
There was a problem hiding this comment.
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
Co-Authored-By: OpenAI Codex <codex@openai.com>
|
|
||
| return ( | ||
| /^!={1,2}/.test(remainder) || | ||
| /^[([.`+\-*/%<>=&|^?,:]/.test(remainder) || |
There was a problem hiding this comment.
Bug: The regex in canContinueStringExpression handles ++ and -- but misses single unary + and - operators, causing incorrect parsing of directive prologues.
Severity: MEDIUM
Suggested Fix
Update the regular expression in canContinueStringExpression to also treat single unary + and - operators as tokens that cannot continue a string expression. This will ensure they are handled consistently with ++ and -- for directive parsing.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/bundler-plugins/src/core/get-code-injection-position.ts#L73
Potential issue: The function `canContinueStringExpression` uses a regular expression to
detect non-continuation tokens after a string expression. This regex explicitly checks
for prefix increment (`++`) and decrement (`--`) operators but fails to account for
single unary plus (`+`) and minus (`-`) operators. As a result, if code like `"use
strict"\n+something` is encountered, the unary plus is not correctly identified as a new
expression, leading to incorrect directive prologue handling. This represents an
incomplete implementation of unary operator detection.
There was a problem hiding this comment.
The bot claims "use strict"\n+something should end the prologue. It should not.

Bundler plugins inject Sentry code into generated bundles. In some outputs the injection could be placed before directive prologues such as
"use strict", causing JavaScript to stop recognizing them as directives.I found this issue to affect some production cases - I don't have access to their sources so I can't fully say how the original code was authored and what exactly made it lose the strict mode, but the generated output looked like this:
Given the sentry code was injected before the strict mode directive, that changed the meaning of
arguments[1]at this position in the app code:That's because in the sloppy mode the assignment to
tbefore thearguments[1]reference changes theargumentscontent too 🫠 . You can test it out using this isolated sample:This PR:
BannePlugincan only prepend/append text, as far as I know, it can't just inject into an arbitrary position. So it was replaced with a compilation hook and ReplaceSource plugin. That allows for a fine-grained control at the asset levelinjectAPI handles this for usAI disclosure: I have steered it a bunch myself and I understand each line of code added. I ensured (using my own judgement) that all of this matches the project's style and goal but ofc I have much less context on that than the maintainers here. That said, I can address any PR feedback thrown my way.