ljharb/qs

Parse results in multiple objects with the same key instead of one.

Open

#241 ouverte le 20 déc. 2017

Voir sur GitHub
 (0 commentaires) (3 réactions) (0 assignés)JavaScript (744 forks)batch import
bughelp wanted

Métriques du dépôt

Stars
 (8 015 stars)
Métriques de merge PR
 (Merge moyen 6j 22h) (2 PRs mergées en 30 j)

Description

The following stringify/parse sequence works as expected:

dataB = {
  "incidents": [
    {
      "open": [
        "damaged",
        {
          "lost": [
            "red",
            "green"
          ]
        }
      ]
    }
  ]
};

queryStringB = QS.stringify(dataB, { arrayFormat: 'brackets' });
parsedB = QS.parse(queryStringB)

The result is {"incidents":[{"open":["damaged",{"lost":["red","green"]}]}]}, which matches dataB.

However, the following sequence does not result how I expect it to:

dataA = {
  "incidents": [
    "cold",
    {
      "open": [
        "damaged",
        {
          "lost": [
            "red",
            "green"
          ]
        }
      ]
    }
  ]
};

queryStringA = QS.stringify(dataA, { arrayFormat: 'brackets' });
parsedA = QS.parse(queryStringA)

This results in {"incidents":["cold",{"open":["damaged"]},{"open":[{"lost":["red","green"]}]}]}, which does not match dataA. Note that the only difference between dataA and dataB is that dataA has an extra element in the incidents array.

I saw some other parsing issues in the issue listing but none of them look quite like this.

Guide contributeur