Skip to content

fix: correctly replace bracked escaped part#4968

Merged
schiller-manuel merged 1 commit intomainfrom
escape-replace
Aug 16, 2025
Merged

fix: correctly replace bracked escaped part#4968
schiller-manuel merged 1 commit intomainfrom
escape-replace

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Aug 16, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Routing now correctly handles bracketed dynamic segments with multiple characters in paths. Contents like [userId] are preserved in full (no longer truncated to a single character), ensuring accurate initial route generation and consistent navigation behavior for dynamic routes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 16, 2025

Walkthrough

A module-scoped regex constant was added and used in determineInitialRoutePath to replace bracketed content in route parts, changing from single-character to multi-character bracket content support. Local regex declaration was removed. No public APIs or error handling logic were altered.

Changes

Cohort / File(s) Summary
Regex refactor in router-generator utils
packages/router-generator/src/utils.ts
Added module-level BRACKET_CONTENT_RE = /[(.*?)]/g; removed local regex; updated replacement to use BRACKET_CONTENT_RE allowing multi-character bracket contents; no exported signatures changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble on brackets, crunch-crunch, hooray!
Multi-char morsels now join the buffet.
Paths grow longer, tidy and neat—
Regex whiskers twitch to the beat.
Hop, hop, ship—my routes are complete! 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch escape-replace

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nx-cloud
Copy link

nx-cloud bot commented Aug 16, 2025

View your CI Pipeline Execution ↗ for commit 61cec50

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 5m 39s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 41s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-16 14:38:09 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 16, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@4968

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@4968

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@4968

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@4968

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@4968

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@4968

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@4968

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@4968

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@4968

@tanstack/react-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@4968

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@4968

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@4968

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@4968

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@4968

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@4968

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@4968

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@4968

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@4968

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@4968

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@4968

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@4968

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@4968

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@4968

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@4968

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@4968

@tanstack/solid-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@4968

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@4968

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@4968

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@4968

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@4968

@tanstack/start-server-functions-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-client@4968

@tanstack/start-server-functions-fetcher

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-fetcher@4968

@tanstack/start-server-functions-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@4968

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@4968

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@4968

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@4968

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@4968

commit: 61cec50

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
packages/router-generator/src/utils.ts (1)

75-96: Fix stateful /g regex reuse (lastIndex) and validate multi-char bracket content correctly.

Because BRACKET_CONTENT_RE is a global regex and used with exec, lastIndex must be reset per string; otherwise matches can be skipped across parts. Also, after switching to multi-char capture, the disallowed-char check should scan each character, not the entire captured string.

Apply this diff to address both issues:

     // Check if any disallowed characters are used in brackets
 
-    let match
-    while ((match = BRACKET_CONTENT_RE.exec(part)) !== null) {
-      const character = match[1]
-      if (character === undefined) continue
-      if (DISALLOWED_ESCAPE_CHARS.has(character)) {
+    let match
+    // Reset global regex state before scanning a new string
+    resetRegex(BRACKET_CONTENT_RE)
+    while ((match = BRACKET_CONTENT_RE.exec(part)) !== null) {
+      const content = match[1] ?? ''
+      const invalidChars = [...new Set([...content].filter((ch) => DISALLOWED_ESCAPE_CHARS.has(ch)))]
+      if (invalidChars.length) {
         console.error(
-          `Error: Disallowed character "${character}" found in square brackets in route path "${routePath}".\nYou cannot use any of the following characters in square brackets: ${Array.from(
+          `Error: Disallowed character(s) "${invalidChars.join(', ')}" found in square brackets in route path "${routePath}".\nYou cannot use any of the following characters in square brackets: ${Array.from(
             DISALLOWED_ESCAPE_CHARS,
           ).join(', ')}\nPlease remove and/or replace them.`,
         )
         process.exit(1)
       }
     }
 
     // Since this split segment is safe at this point, we can
     // remove the brackets and replace them with the content inside
     return part.replace(BRACKET_CONTENT_RE, '$1')

Notes:

  • resetRegex is already defined in this file and safely resets lastIndex.
  • String.prototype.replace with a global regex resets lastIndex internally, so no extra reset is required before the replace.
🧹 Nitpick comments (1)
packages/router-generator/src/utils.ts (1)

55-56: Good extraction to a module-scoped regex; consider disallowing empty brackets.

Defining BRACKET_CONTENT_RE once at module scope is cleaner and avoids per-call allocations. Minor: if empty brackets "[]" are not a valid case, prefer (.+?) over (.*?) to enforce at least one character inside the brackets.

Apply this minimal tweak if empties should be invalid:

-const BRACKET_CONTENT_RE = /\[(.*?)\]/g
+const BRACKET_CONTENT_RE = /\[(.+?)\]/g
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 74be286 and 61cec50.

📒 Files selected for processing (1)
  • packages/router-generator/src/utils.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview

@schiller-manuel schiller-manuel merged commit f6fcb1b into main Aug 16, 2025
6 checks passed
@schiller-manuel schiller-manuel deleted the escape-replace branch August 16, 2025 15:24
tannerlinsley pushed a commit that referenced this pull request Aug 26, 2025
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Routing now correctly handles bracketed dynamic segments with multiple
characters in paths. Contents like [userId] are preserved in full (no
longer truncated to a single character), ensuring accurate initial route
generation and consistent navigation behavior for dynamic routes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
naoya7076 pushed a commit to naoya7076/router that referenced this pull request Feb 15, 2026
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Routing now correctly handles bracketed dynamic segments with multiple
characters in paths. Contents like [userId] are preserved in full (no
longer truncated to a single character), ensuring accurate initial route
generation and consistent navigation behavior for dynamic routes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant