Skip to content

Method stringifyUrl duplicates query params in some cases #409

@ekabolotina

Description

@ekabolotina

The docs of stringifyUrl method say:

Query items in the query property overrides queries in the url property

But internally when it parses the query from url, it ignores the parsing options passed to stringifyUrl (for example, arrayFormat). This leads to duplicate query keys in the final url.

For example:

const currentUrl = 'https://localhost:3000/?arr[]=item1';

const newUrl = qs.stringifyUrl(
  {
    url: currentUrl,
    query: { arr: ['item1', 'item2'] },
  },
  {
    arrayFormat: 'bracket',
    skipEmptyString: true,
    skipNull: true,
  }
);

The expected value is https://localhost:3000/?arr[]=item1&arr[]=item2.
But the final result is https://localhost:3000/?arr[]=item1&arr[]=item2&arr%5B%5D=item1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions