[PR #4792] [MERGED] fix: preserve encoded characters in cURL URLs #4934

Closed
opened 2026-03-17 02:25:30 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/4792
Author: @xTudoS
Created: 2/27/2025
Status: Merged
Merged: 7/24/2025
Merged by: @jamesgeorge007

Base: nextHead: fix/allow-encoded-slash


📝 Commits (3)

  • 8335889 Remove decodeURIComponent allowing encoded chars
  • a626662 chore: check environment present in curl
  • 866c7d5 chore: cleanup

📊 Changes

1 file changed (+23 additions, -1 deletions)

View changed files

📝 packages/hoppscotch-common/src/helpers/curl/curlparser.ts (+23 -1)

📄 Description

Closes https://github.com/hoppscotch/hoppscotch/issues/4769

Some APIs may use encoded chars in their endpoints, if I'm importing a command, it is expected that it remains the same without any changes in the request scope.

When importing a cURL request into Hoppscotch, encoded characters like %2F were being decoded to /, altering the intended URL structure. This caused issues with APIs that require specific encoded characters in their endpoints.

For instance:

curl --request GET --url 'https://gitlab.com/api/v4/projects/278964/repository/files/changelogs%2FREADME.md?ref=master'

Fix

  • Introduced logic to check if the URL contains environment variables using a regex pattern <<variable_name>>.

  • If environment variables are present, we apply decodeURIComponent carefully to avoid decoding those placeholders.

  • If no environment variables are present, encoded characters are preserved in the URL as-is.

What’s Changed:

Replaced unconditional decoding with a conditional strategy that preserves encoded characters unless decoding is explicitly safe.

Introduced a helper containsEnvVariables() and supporting regex for environment variable detection.

Notes to reviewers

This PR do not fix the code generation because code generation is another repository
For code generation fix, I have open this PR https://github.com/hoppscotch/httpsnippet/pull/4


🔄 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/hoppscotch/hoppscotch/pull/4792 **Author:** [@xTudoS](https://github.com/xTudoS) **Created:** 2/27/2025 **Status:** ✅ Merged **Merged:** 7/24/2025 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `next` ← **Head:** `fix/allow-encoded-slash` --- ### 📝 Commits (3) - [`8335889`](https://github.com/hoppscotch/hoppscotch/commit/833588968fe23cda4dfa258ea21030e96080d51a) Remove decodeURIComponent allowing encoded chars - [`a626662`](https://github.com/hoppscotch/hoppscotch/commit/a6266628becd258de164f105956822acc4669537) chore: check environment present in curl - [`866c7d5`](https://github.com/hoppscotch/hoppscotch/commit/866c7d5fdafc2cef8cc7141476a78fbd5bc5c388) chore: cleanup ### 📊 Changes **1 file changed** (+23 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/helpers/curl/curlparser.ts` (+23 -1) </details> ### 📄 Description Closes https://github.com/hoppscotch/hoppscotch/issues/4769 Some APIs may use encoded chars in their endpoints, if I'm importing a command, it is expected that it remains the same without any changes in the request scope. When importing a cURL request into Hoppscotch, encoded characters like `%2F` were being decoded to `/`, altering the intended URL structure. This caused issues with APIs that require specific encoded characters in their endpoints. For instance: ```bash curl --request GET --url 'https://gitlab.com/api/v4/projects/278964/repository/files/changelogs%2FREADME.md?ref=master' ``` ### Fix - Introduced logic to check if the URL contains environment variables using a regex pattern `<<variable_name>>`. - If environment variables are present, we apply decodeURIComponent carefully to avoid decoding those placeholders. - If no environment variables are present, encoded characters are preserved in the URL as-is. ### What’s Changed: Replaced unconditional decoding with a conditional strategy that preserves encoded characters unless decoding is explicitly safe. Introduced a helper `containsEnvVariables()` and supporting regex for environment variable detection. ### Notes to reviewers <!-- Any information you feel the reviewer should know about when reviewing your PR --> This PR do not fix the code generation because code generation is another repository For code generation fix, I have open this PR https://github.com/hoppscotch/httpsnippet/pull/4 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:25:30 +03: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/hoppscotch#4934
No description provided.