mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 01:06:00 +03:00
[PR #5041] [MERGED] fix(common): url and param encoding #5030
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5030
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5041
Author: @CuriousCorrelation
Created: 5/2/2025
Status: ✅ Merged
Merged: 5/8/2025
Merged by: @jamesgeorge007
Base:
patch← Head:common-fix-path-encoding📝 Commits (2)
a09ec44fix(common): url and param encoding4eba8cbfix(common): convertparamstype regardless📊 Changes
1 file changed (+29 additions, -6 deletions)
View changed files
📝
packages/hoppscotch-common/src/helpers/functional/process-request.ts(+29 -6)📄 Description
These changes fix URL parameter encoding behavior based on how parameter values are encoded, those based on the
ENCODE_MODEsetting.Closes HFE-833
Closes #4971
Context: We encode query parameter values according to RFC 3986 Section 3.4, query components should be encoded, which is controlled by
ENCODE_MODEsetting.When the encoding mode was set to "enable", a parameter value like
{second-testing}would be encoded to%257Bsecond-testing%257Dinstead of%7Bsecond-testing%7D.This occurred because of a combination of the custom encoding logic and the browser's native
searchParams.append()method.As in RFC 3986#2.4, percent-encoding is non-idempotent. When processing a URL like
http://localhost:8080/%7Bfoo%7D, thedecodeURIComponentcall applied to the URL would revert the encoded path back tohttp://localhost:8080/{foo}.This fix addresses all issues by modifying the impl to maintain compliance with URL standards:
The
processParamsfunction now only encodes values:The
updateUrlfunction now manually constructs query parameters:The URL string generation doesn't apply
decodeURIComponentto the entire URL:Notes to reviewers
Test by making requests with special characters in parameters using different
ENCODE_MODEsettings ("enable", "disable", and "auto"), then look for URLs with already encoded segments like%7Bfoo%7Dwhich should remain encoded throughout the process.Demo
Below are the actual logs from testing this fix with different
ENCODE_MODEsettings and URL formats:With unencoded URL path and ENCODE_MODE="disable":
With unencoded URL path and ENCODE_MODE="enable":
With already encoded URL path and ENCODE_MODE="enable":
With already encoded URL path and ENCODE_MODE="disable":
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.