Skip to content

fix(rules): restrict jQuery patterns to resource URLs - #31

Merged
setube merged 2 commits into
setube:mainfrom
Jacobinwwey:fix/jquery-resource-scope
Oct 17, 2026
Merged

setube merged 2 commits into
setube:mainfrom
Jacobinwwey:fix/jquery-resource-scope

Conversation

@Jacobinwwey

@Jacobinwwey Jacobinwwey commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

1. Context & Motivation (Context)

  • Issue: No linked issue; reproducible false positive.
  • Problem: Both the frontend and dynamic jQuery patterns accept jquery. and, without matchIn, search page HTML or combined snapshot text. Ordinary body/title prose such as A tutorial about jQuery. is therefore reported as jQuery usage.
  • Trade-offs: Limit textual signatures to resource URLs. This deliberately drops prose and inline-text hints while keeping explicit runtime globals and resource-derived versions.

2. Implementation Details (Implementation)

  • Add matchIn: ["resources"] to both existing jQuery rules; no matcher changes.
  • Run the actual injected detector and dynamic snapshot matcher for negative prose/title, positive global and positive resource cases.

3. Testing Strategies (Validation)

  • node --test tests/jquery-detection.test.mjs: both tests pass on this branch. The new dynamic-title regression failed before applying the resource scope.
  • A jQuery global still matches; jquery-3.7.1.min.js still reports version 3.7.1.
  • Combined fork validation passes 36 unit tests; the SDK candidate also passed 13 Chrome integration tests, lint, typecheck and production build. The follow-up changes an extension-only dynamic rule excluded from the SDK payload.
  • Performance: Narrows the existing matching input; introduces no dependency or additional traversal.

Signed-off-by: aliyun1121003339 <jacob.hxx.cn@outlook.com>
@sourcery-ai

sourcery-ai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
审查者指南(小型 PR 中默认折叠)

审查者指南

此 PR 将现有 jQuery 规则的匹配范围限定为资源 URL,以消除对普通文本的误报,同时通过针对性的规则测试框架测试,保留对运行时全局变量和带版本号资源的检测。

文件级变更

变更 详情 文件
将 jQuery 文本特征的匹配范围限制为已检测到的资源 URL,同时保留显式的运行时全局变量检测。
  • 为现有 jQuery 规则添加仅匹配资源的范围,不更改匹配器逻辑。
  • 验证普通文本不再触发 jQuery 检测,同时仍支持对全局变量和带版本号的脚本资源进行检测。
public/rules/page/frontend-frameworks.json
增加测试框架覆盖,验证误报回归问题已修复,且既有检测能力得以保留。
  • 通过规则测试框架,对普通文本、jQuery 全局变量以及带版本号的 jQuery 资源运行注入的页面检测器。
  • 断言普通文本不会被检测,并能从资源 URL 中提取版本号 3.7.1。
tests/jquery-detection.test.mjs

提示与命令

使用 Sourcery

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 根据审查评论创建 GitHub issue: 回复该审查评论,请 Sourcery 根据评论创建 issue。也可以回复 @sourcery-ai issue 来创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。也可以在拉取请求中评论 @sourcery-ai title,以(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中想要生成摘要的位置写入 @sourcery-ai summary,即可随时在该位置生成 PR 摘要。也可以在拉取请求中评论 @sourcery-ai summary,以(重新)生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已处理完所有评论且不想再看到它们,这会很有用。
  • 关闭所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,即可关闭所有现有的 Sourcery 审查。如果你想从头开始进行新的审查,这尤其有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义体验

访问你的仪表板以:

  • 启用或停用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR narrows the existing jQuery rule to resource URLs to eliminate prose false positives, while retaining runtime-global and versioned resource detection through targeted rule-harness tests.

File-Level Changes

Change Details Files
Restrict the jQuery text signature to detected resource URLs while preserving explicit runtime-global detection.
  • Add a resources-only match scope to the existing jQuery rule without changing matcher logic.
  • Verify prose no longer produces a jQuery detection while global and versioned script-resource detections remain supported.
public/rules/page/frontend-frameworks.json
Add harness coverage for the false-positive regression and preserved detections.
  • Execute the injected page detector through the rule harness for prose, the jQuery global, and a versioned jQuery resource.
  • Assert rejection of prose and extraction of version 3.7.1 from the resource URL.
tests/jquery-detection.test.mjs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨——我发现了 1 个问题

给 AI Agent 的提示
请处理这次代码审查中的评论:

## 单条评论

### 评论 1
<location path="tests/jquery-detection.test.mjs" line_range="7" />
<code_context>
+
+test('the extension detector rejects jQuery prose while preserving runtime and resource hits', async () => {
+  const rules = loadPageRules(['page/frontend-frameworks.json'])
+  const prose = await runPageDetector(rules, { html: '<p>A tutorial about jQuery.</p>' })
+  assert.ok(!prose.some(technology => technology.name === 'jQuery'))
+  const runtime = await runPageDetector(rules, { globals: ['jQuery'] })
</code_context>
<issue_to_address>
**教程标题仍会触发 jQuery 检测**

当页面标题包含“A tutorial about jQuery.”之类的描述性文本时,`detectFromDynamicSnapshot` 也会运行 `dynamicTechnologies` 中单独的 jQuery 规则;由于该规则没有 `matchIn`,`applyDynamicRuleList` 会搜索合并后的快照文本(包括标题),因此像“A tutorial about jQuery.”这样的标题也会被报告为 jQuery。注入式检测器的断言仍然会通过。

请同样将重复的 `dynamicTechnologies` jQuery 规则限制为仅匹配资源 URL,并添加回归测试覆盖该快照路径。
</issue_to_address>

Sourcery 为开源项目免费提供服务——如果您喜欢我们的审查,请考虑分享 ✨
Original comment in English

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/jquery-detection.test.mjs" line_range="7" />
<code_context>
+
+test('the extension detector rejects jQuery prose while preserving runtime and resource hits', async () => {
+  const rules = loadPageRules(['page/frontend-frameworks.json'])
+  const prose = await runPageDetector(rules, { html: '<p>A tutorial about jQuery.</p>' })
+  assert.ok(!prose.some(technology => technology.name === 'jQuery'))
+  const runtime = await runPageDetector(rules, { globals: ['jQuery'] })
</code_context>
<issue_to_address>
**Tutorial titles still trigger jQuery**

When the page title contains prose such as “A tutorial about jQuery.”, `detectFromDynamicSnapshot` also runs the separate jQuery rule in `dynamicTechnologies`; because that rule has no `matchIn`, `applyDynamicRuleList` searches the combined snapshot text, including the title, and reports jQuery for a title such as “A tutorial about jQuery.” The injected-detector assertion still passes.

Restrict the duplicate `dynamicTechnologies` jQuery rule to resource URLs as well, and cover that snapshot path with a regression test.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/jquery-detection.test.mjs Resolved
Signed-off-by: aliyun1121003339 <jacob.hxx.cn@outlook.com>
@setube
setube merged commit 2ac8f30 into setube:main Oct 17, 2026
1 check passed
setube added a commit that referenced this pull request Oct 21, 2026
收录 Vue Devtools 误报修复(#34)、PR #30/#31/#32 修复和 #33 SDK,page-support.ts 按 Prettier 换行。

将版本号提升到 1.3.91。
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.

2 participants