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

Symbol keys are not preserved when data is being passed to transformRequest #6392

Open
legowerewolf opened this issue May 14, 2024 · 0 comments

Comments

@legowerewolf
Copy link

Describe the bug

In the app I work on, when I make a request with a payload, I want that request to be transformed almost all of the time. Most of this transformation involves transforming keys in objects from pascalCase to snake_case (and back again when the request resolves). I think this is a stupid decision, but I didn't make it and I can't correct it myself.

In order to handle that transformation, we use the transformRequest option when we construct a customized global client object.

I intended to add a Symbol key to the payload object as a way to signal "don't transform this or its descendants" when it sees that key, but the problem is that by the time the transformer function gets the payload, that key has already been stripped. I think this is a bug.

To Reproduce

https://codesandbox.io/p/sandbox/goofy-boyd-qwmxw5

Code snippet

import axios from "axios";

const client = axios.create({
  transformRequest(data) {
    console.log("transformRequest", data);
    return data;
  },
});

const symbolKey = Symbol("example");

console.log(`Axios version: ${axios.VERSION}`);

(async () => {
  const payload = {
    [symbolKey]: "value",
    stringKey: "value",
  };

  console.log("payload as submitted", payload);

  const { data } = await client.post("https://httpbin.org/post", payload);

  console.log(data);
})();

Expected behavior

I expect to see the key [Symbol('example')] in both the "payload as submitted" and "transformRequest" log lines.

Axios Version

1.6.8

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

No response

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

1 participant