Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios automatically decodes slashes in my path parameters #6712

Open
gerhardadler opened this issue Nov 25, 2024 · 1 comment
Open

Axios automatically decodes slashes in my path parameters #6712

gerhardadler opened this issue Nov 25, 2024 · 1 comment

Comments

@gerhardadler
Copy link

gerhardadler commented Nov 25, 2024

Describe the bug

When using an URIencoded string in my url, Axios automatically decodes the slashes.

To Reproduce

See code snippet

Code snippet

const deviceId = 'very/cool/device/å';
const encodedDeviceId = encodeURIComponent(deviceId); // very/cool/device/å

// the request goes to "http://localhost/search/very/cool/device/å", giving me a 404 error
axios.get('http://localhost/search/'   encodedDeviceId)
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

Expected behavior

I would expect Axios to not decode the slashes in my URL, and the request going to http://localhost/search/very/cool/device/å

Axios Version

v0.29.0

Adapter Version

XHR/HTTP

Browser

Firefox, Chromium

Browser Version

132, 131

Node.js Version

v22.10.0

OS

Windows 10, openSUSE Tumbleweed

Additional Library Versions

No response

Additional context/Screenshots

No response

@GhostHunterr
Copy link

Hi,

Instead of encoding the entire deviceId, you can split the deviceId by / and then encode each part individually and at the end join them by slashes.
This way, the slashes are not encoded in the URL.

Here’s an example:

// Split deviceId by '/' and encode each part
const deviceId = 'very/cool/device/å';
const deviceParts = deviceId.split('/').map(encodeURIComponent);
const encodedDeviceId = deviceParts.join('/'); // very/cool/device/å

axios.get('http://localhost/search/'   encodedDeviceId)
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

This should resolve the issue.

Hope this helps!

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

No branches or pull requests

2 participants