ljharb/qs

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

Open

#241 创建于 2017年12月20日

在 GitHub 查看
 (0 评论) (3 反应) (0 负责人)JavaScript (8,015 star) (744 fork)batch import
bughelp wanted

描述

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.

贡献者指南

Parse results in multiple objects with the same key instead of one. · ljharb/qs#241 | Good First Issue