Skip to content

refactor: simplify posts route tag handling#105

Merged
AlejandroAkbal merged 1 commit intomainfrom
auto-triage/326-app-routing-simplify
Mar 16, 2026
Merged

refactor: simplify posts route tag handling#105
AlejandroAkbal merged 1 commit intomainfrom
auto-triage/326-app-routing-simplify

Conversation

@AlejandroAkbal
Copy link
Member

@AlejandroAkbal AlejandroAkbal commented Mar 15, 2026

Summary

  • remove redundant manual tag encode/decode in posts route handling and rely on the existing qs router query serializer/parser
  • keep the |-joined tag format while simplifying both posts pages and RouterHelper behavior
  • update router-helper coverage to assert raw query-object values instead of double-handled encoded strings

Validation

  • File-level readback confirmed the intended changes in RouterHelper, both posts pages, and router-helper tests
  • Runtime test execution in the isolated worktree was blocked because the fresh worktree lacks linked Vitest binaries and generated .nuxt/tsconfig.json
  • Prior targeted validation for this exact change passed before isolation via pnpm exec vitest run test/assets/router-helper.test.ts

Summary by CodeRabbit

  • Bug Fixes

    • Updated tag parameter handling in URLs to display special characters in raw format instead of percent-encoded sequences.
  • Tests

    • Updated test expectations to align with updated tag parameter formatting in URLs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

Walkthrough

The PR removes URL encoding and decoding transformations for tag names across routing and tag processing logic. Tag names are now passed as raw values without encodeURIComponent/decodeURIComponent in route generation and URL query parsing. Tests updated to reflect this behavior.

Changes

Cohort / File(s) Summary
Route generation logic
assets/js/RouterHelper.ts
Removed encodeURIComponent call on tag names when constructing the tags query parameter. Tags now passed as raw name values.
Tag processing in page components
pages/posts/[domain].vue, pages/premium/saved-posts/[domain].vue
Removed decodeURIComponent step when parsing tags from URL query string. Tags converted directly from raw query values without decoding.
Router helper tests
test/assets/router-helper.test.ts
Updated test expectations to match raw (non-encoded) tag values. Test cases no longer include percent-encoded characters (e.g., %26) and compare against raw query strings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • fix: encode ampersands in post tag routes #85: Directly related—modifies the same generatePostsRoute function and tag encoding/decoding logic in page components, but implements opposite behavior by adding URL encoding rather than removing it.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: removing redundant encode/decode logic to simplify tag handling in posts route logic across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch auto-triage/326-app-routing-simplify
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch auto-triage/326-app-routing-simplify
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/assets/router-helper.test.ts (1)

24-44: 🛠️ Refactor suggestion | 🟠 Major

Add an explicit regression test for | inside a tag name

Current coverage misses the separator-collision edge case. Add a test that documents/enforces expected behavior when a tag includes | (e.g., throw, escape, or alternate encoding), so this does not regress silently.

Example test shape
+  it('rejects tag names containing the "|" separator', () => {
+    expect(() =>
+      generatePostsRoute(
+        '/posts',
+        'safebooru.org',
+        undefined,
+        [new Tag({ name: 'foo|bar' })],
+        undefined
+      )
+    ).toThrow()
+  })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/assets/router-helper.test.ts` around lines 24 - 44, Add a regression
test to ensure generatePostsRoute does not treat a literal '|' inside a Tag name
as the separator: create a Tag with a name containing '|' (e.g., new Tag({ name:
'foo|bar' })), call generatePostsRoute with multiple tags including that tag,
then assert that the resulting route.query.tags preserves that tag as a single
value (i.e., the '|' is escaped/encoded or otherwise not split) by checking
String(route.query?.tags) and toMatchObject so future changes to the router
serialization won’t silently split or lose the pipe character.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@test/assets/router-helper.test.ts`:
- Around line 24-44: Add a regression test to ensure generatePostsRoute does not
treat a literal '|' inside a Tag name as the separator: create a Tag with a name
containing '|' (e.g., new Tag({ name: 'foo|bar' })), call generatePostsRoute
with multiple tags including that tag, then assert that the resulting
route.query.tags preserves that tag as a single value (i.e., the '|' is
escaped/encoded or otherwise not split) by checking String(route.query?.tags)
and toMatchObject so future changes to the router serialization won’t silently
split or lose the pipe character.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 03039255-5fb2-43f3-b573-67d02b9dfc8a

📥 Commits

Reviewing files that changed from the base of the PR and between 5cc34fe and 22e199d.

📒 Files selected for processing (4)
  • assets/js/RouterHelper.ts
  • pages/posts/[domain].vue
  • pages/premium/saved-posts/[domain].vue
  • test/assets/router-helper.test.ts
💤 Files with no reviewable changes (2)
  • pages/premium/saved-posts/[domain].vue
  • pages/posts/[domain].vue


if (tags != null && Array.isArray(tags) && tags.length) {
route.query.tags = tags.map((tag) => encodeURIComponent(tag.name)).join('|')
route.query.tags = tags.map((tag) => tag.name).join('|')
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Prevent separator-collision in tag serialization

Line 25 joins raw tag names with |, so any tag containing | becomes lossy/ambiguous when parsed back. This silently corrupts filtering for that input.

Proposed defensive fix
   if (tags != null && Array.isArray(tags) && tags.length) {
+    if (tags.some((tag) => tag.name.includes('|'))) {
+      throw new Error('Tag names cannot contain "|" because it is used as the route separator')
+    }
     route.query.tags = tags.map((tag) => tag.name).join('|')
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
route.query.tags = tags.map((tag) => tag.name).join('|')
if (tags != null && Array.isArray(tags) && tags.length) {
if (tags.some((tag) => tag.name.includes('|'))) {
throw new Error('Tag names cannot contain "|" because it is used as the route separator')
}
route.query.tags = tags.map((tag) => tag.name).join('|')
}

@AlejandroAkbal
Copy link
Member Author

Following up on the CodeRabbit suggestion about handling literal | in tag names.

I intentionally did not apply that change in this PR.

Reason:

  • In the current app/API contract, | is the reserved multi-tag delimiter.
  • This PR only simplifies redundant encode/decode handling around the existing contract.
  • Supporting a literal | inside one tag would require a broader protocol change across multiple places, not a small local fix here.

That delimiter behavior is currently baked into:

  • assets/js/RouterHelper.ts (join('|'))
  • pages/posts/[domain].vue / pages/premium/saved-posts/[domain].vue (split('|'))
  • API query forwarding in the same pipe-delimited format
  • history/title rendering that also interprets | as a separator
  • existing multi-tag test expectations like cat|black_hair

So for this PR, I left the delimiter contract unchanged on purpose. If we want to support literal | in tag names, that should be handled as a separate protocol-level change with explicit escaping/unescaping rules across App + API + history handling.

@AlejandroAkbal AlejandroAkbal merged commit df24fbc into main Mar 16, 2026
1 check passed
@AlejandroAkbal AlejandroAkbal deleted the auto-triage/326-app-routing-simplify branch March 16, 2026 03:08
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.

1 participant