Skip to content

fix(common): preserve Unicode beside malformed URL escapes - #9753

Open
0718lol wants to merge 1 commit into
usebruno:mainfrom
0718lol:bugfix/unicode-path-percent-escapes
Open

0718lol wants to merge 1 commit into
usebruno:mainfrom
0718lol:bugfix/unicode-path-percent-escapes

Conversation

@0718lol

@0718lol 0718lol commented Nov 4, 2026 •

Copy link
Copy Markdown

Description

Preserve percent-encoded Unicode in URL paths when another escape in the same segment is malformed.

Problem

Fixes #9752.

With URL Encoding enabled, /Jos%C3%A9% becomes /Jos%25C3%25A9%25, changing the requested resource. decodeURIComponent rejects the trailing bare percent, and the fallback cannot decode é one UTF-8 byte at a time. Chinese and emoji paths fail the same way.

Fix

In the fallback only, match complete two-, three- and four-byte UTF-8 character candidates before trying individual encoded bytes. decodeURIComponent still validates each candidate; malformed UTF-8 stays verbatim for the existing path encoder to escape safely. The normal decoding path and query-parameter double-encoding contract are unchanged.

Both the CLI and Electron network handlers already call this shared encodeUrl, so no runtime-specific copy needs updating. Add four regression cases for accented, Chinese and emoji paths and an invalid byte preceding valid UTF-8. Each also checks the existing query encoding behavior.

Validation

Node 24.22.1 on macOS arm64, dependencies from the frozen npm lockfile (scoped common/lang workspaces plus root tooling).

  • Before the fix: URL suite 4 failed, 90 passed.
  • After: all bruno-common suites 24 passed, 742 tests passed, 4 snapshots passed (npm test --workspace=packages/bruno-common -- --runInBand).
  • npm run build:bruno-common: passed, including CJS/ESM bundles and declarations.
  • ESLint on both changed files and git diff --check: passed.
  • Real loopback HTTP probe using the built common package: received /José%, /中%ZZ and /😀% as intended.
  • Ran the repository's code-review skill across all six applicable lenses: correctness, security, architecture, conventions, cross-platform and feature parity; no findings.

The scoped install nests TypeScript under bruno-common, so build/lint used that directory in NODE_PATH to resolve existing tooling peer dependencies. No dependency manifests or lockfiles changed. No full Electron UI or packaged CLI journey was run; verification covers the shared encoder and actual loopback requests through its built output.

Screenshots

Not applicable to the shared encoding utility. Example: https://example.com/Jos%C3%A9% now produces https://example.com/Jos%C3%A9%25 instead of https://example.com/Jos%25C3%25A9%25.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have tested these changes locally and confirmed they work as expected.
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.
  • I've run the claude code review skill locally.

Codex assisted with discovery, implementation, verification, independent review and drafting.

Summary by CodeRabbit

  • Bug Fixes
    • Improved URL handling when paths contain valid percent-encoded Unicode alongside malformed escape sequences. Valid sequences are preserved, and malformed percent signs are safely encoded.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The URL decoder fallback now matches complete UTF-8 percent-encoded sequences before individual escapes. Regression tests cover malformed and invalid escapes beside valid encoded Unicode in paths.

Changes

URL encoding fallback

Layer / File(s) Summary
UTF-8 fallback and regression coverage
packages/bruno-common/src/utils/url/index.ts, packages/bruno-common/src/utils/url/index.spec.ts
safeDecodeURIComponent matches complete UTF-8 escape sequences in its fallback. Tests verify path encoding with malformed or invalid escapes beside valid encoded Unicode, and preserve the existing query encoding behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • usebruno/bruno#9630: Adds URL-encoding coverage for encoded and Unicode paths in HTTP/2 request flows that use the shared encodeUrl function.

Suggested reviewers: bijin-bruno, shubh-bruno

Merge Risk: Minimal · up to 1b42a

No merge-blocking issue was identified in the changed URL encoding behavior.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: Unicode beside malformed URL escapes is preserved, scoped to the shared common package. It matches the raw summary of the safeDecodeURIComponent fallback and the added enco…
Linked Issues check Passed Issue #9752 requires a focused shared URL-encoder fix and regression tests. safeDecodeURIComponent now matches complete two-, three-, and four-byte UTF-8 escape sequences before byte-level fallback.…
Out of Scope Changes check Passed The diff changes only packages/bruno-common/src/utils/url/index.ts and its focused test file. The production change supports issue #9752, and the added tests verify the requested path behavior and u…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the change: Unicode beside malformed URL escapes is preserved, scoped to the shared common package. It matches the raw summary of the safeDecodeURIComponent fallback and the added encodeUrl regression tests, and it matches the linked issue #9752 objective.

Full details: Linked Issues check

Explanation

Issue #9752 requires a focused shared URL-encoder fix and regression tests. safeDecodeURIComponent now matches complete two-, three-, and four-byte UTF-8 escape sequences before byte-level fallback. The tests cover accented, Chinese, emoji, and invalid-byte-before-valid-UTF-8 paths. Each test also verifies that ?redirect=%20 remains ?redirect=%2520. The reported common-package test and build results support the implementation.

Full details: Out of Scope Changes check

Explanation

The diff changes only packages/bruno-common/src/utils/url/index.ts and its focused test file. The production change supports issue #9752, and the added tests verify the requested path behavior and unchanged query encoding. No dependency, runtime-specific, or unrelated feature changes appear in the reviewed diff.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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

UTF-8 escapes stay together
A stray percent takes its place
Paths keep their encoded letters
Tests check each tricky case
Query spaces keep their rule
The fallback handles the rest

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between ec84bc0 and 1b42aae.

Files selected for processing: 2
  • packages/bruno-common/src/utils/url/index.spec.ts
  • packages/bruno-common/src/utils/url/index.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

URL encoder double-encodes Unicode paths beside malformed percent escapes

1 participant