[PR #696] [MERGED] fix: anchor has/missing condition value regex for full-string matching #778

Closed
opened 2026-05-06 13:10:03 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/696
Author: @southpolesteve
Created: 3/27/2026
Status: Merged
Merged: 3/27/2026
Merged by: @southpolesteve

Base: mainHead: fix/anchor-has-missing-condition-regex


📝 Commits (1)

  • cc17d69 fix: anchor has/missing condition value regex for full-string matching

📊 Changes

2 files changed (+65 additions, -1 deletions)

View changed files

📝 packages/vinext/src/config/config-matchers.ts (+4 -1)
📝 tests/shims.test.ts (+61 -0)

📄 Description

Summary

Config rule has/missing conditions now use anchored regex (^value$) for value matching, preventing partial substring matches.

Details

Previously, _cachedConditionRegex() compiled the condition value as an unanchored regex via safeRegExp(value). This meant a condition like has: [{ type: "cookie", key: "role", value: "admin" }] would match any cookie value containing "admin" as a substring (e.g., "not-admin", "admin-temp").

The fix anchors the regex with ^ and $, matching Next.js behavior (prepare-destination.ts uses new RegExp(\^${hasItem.value}$`)`).

Regex patterns in condition values continue to work correctly since anchoring just constrains them to match the full value.

Tests

Adds 4 tests:

  • Exact value matches fully
  • Does not match substring
  • Does not match superstring
  • Regex patterns still work with anchoring

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/696 **Author:** [@southpolesteve](https://github.com/southpolesteve) **Created:** 3/27/2026 **Status:** ✅ Merged **Merged:** 3/27/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `fix/anchor-has-missing-condition-regex` --- ### 📝 Commits (1) - [`cc17d69`](https://github.com/cloudflare/vinext/commit/cc17d691570d01c03044cedbfe2dd64f5516f5ad) fix: anchor has/missing condition value regex for full-string matching ### 📊 Changes **2 files changed** (+65 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/config/config-matchers.ts` (+4 -1) 📝 `tests/shims.test.ts` (+61 -0) </details> ### 📄 Description ## Summary Config rule `has`/`missing` conditions now use anchored regex (`^value$`) for value matching, preventing partial substring matches. ## Details Previously, `_cachedConditionRegex()` compiled the condition value as an unanchored regex via `safeRegExp(value)`. This meant a condition like `has: [{ type: "cookie", key: "role", value: "admin" }]` would match any cookie value *containing* "admin" as a substring (e.g., "not-admin", "admin-temp"). The fix anchors the regex with `^` and `$`, matching Next.js behavior (`prepare-destination.ts` uses `new RegExp(\`^\${hasItem.value}$\`)`). Regex patterns in condition values continue to work correctly since anchoring just constrains them to match the full value. ## Tests Adds 4 tests: - Exact value matches fully - Does not match substring - Does not match superstring - Regex patterns still work with anchoring --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:10:03 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#778
No description provided.