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

Breaking behavior in params serialization in 0.28.0 #6274

Open
rchl opened this issue Mar 4, 2024 · 7 comments
Open

Breaking behavior in params serialization in 0.28.0 #6274

rchl opened this issue Mar 4, 2024 · 7 comments

Comments

@rchl
Copy link

rchl commented Mar 4, 2024

Describe the bug

In 0.28.0 there is a breaking change to params serialization that wasn't mentioned as such in the changelog.

Probably related to c05ad48 and 807918b

If this is an expected change then it should have been noted in the changelog as breaking. Otherwise it should be fixed.

@DigitalBrainJS

To Reproduce

Send a get request with one of the params values being an object with key/value properties.

Code snippet

axios.get('foo', {
                params: {
                    p: {a: 'z'}
                },
            });

Expected behavior

Previously the p param would be serialized as such: &p={"a":"z"}
With 0.28.0: &p[a]=z

Axios Version

0.28.0

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

@odGit
Copy link

odGit commented Mar 21, 2024

Might be a duplicate of #6262

@briwa
Copy link

briwa commented Mar 29, 2024

I think we can close this since #6263 which is to solve #6262 is merged and released in v0.28.1. See: 3021e0d

@rchl
Copy link
Author

rchl commented Apr 2, 2024

No, it's not fixed. Just tested with 0.28.1.

Feel free to test yourself by making a request like in the initial comment and checking brower network inspector for what is being sent.
I've tried it on an client side (in a browser environment).

@briwa
Copy link

briwa commented Apr 3, 2024

@rchl I see, perhaps it is a different issue. v0.28.1 allows you to have a custom paramsSerializer.serialize options which you could use to achieve what you expected, otherwise I'd say this is just a standardization, i.e. stringified params vs params by key

@rchl
Copy link
Author

rchl commented Apr 3, 2024

Would make sense to keep the old behavior to prevent breaking changes unless there is a good reason to deviate. And if there is then it should be clearly marked as a breaking change and there should be good reason for it (standards compliance or similar).

@butchtm
Copy link

butchtm commented May 3, 2024

@briwa @rchl would anyone have an serializer options example that would restore the behavior to the version prior to 0.28?

@haydenk82
Copy link

@butchtm I've tried to replicate the serialization behavior that was implemented in prior versions to 0.28 below

/**
 * Creates a URL-encoded query string from a given set of parameters
 * @param {Object} params The parameters to encode into a query string
 * @returns {string} The URL-encoded query string
 */
function createQueryString(params: any): string {
    return Object.keys(params).reduce((x, key) => {
        const value = params[key];
        if (typeof value === 'object' && value !== null && !(value instanceof Date)) {
            return x + `${x.length ? '&' : ''}${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value))}`;
        } else {
            return x + `${x.length ? '&' : ''}${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
        }
    }, '');
}

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

5 participants