Skip to content

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

@legowerewolf

Description

@legowerewolf

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

Metadata

Metadata

Assignees

Labels

issue::bugThis issue is related to a bug that requires fixing

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions