]> git.bitcoin.ninja Git - youtube-dl/commit
[utils] Don't attempt to coerce JS strings to numbers in js_to_json (#26851)
authorKevin O'Connor <kevin.oconnor7@gmail.com>
Sat, 17 Oct 2020 17:10:41 +0000 (13:10 -0400)
committerGitHub <noreply@github.com>
Sat, 17 Oct 2020 17:10:41 +0000 (00:10 +0700)
commit4eda10499e8db831167062b0e0dbc7d10d34c1f9
treec0afe01daf906bd9b7f0568eb9cce49e24f15d45
parent605535776a8d5beba78b4d1b057d5206ddd969eb
[utils] Don't attempt to coerce JS strings to numbers in js_to_json (#26851)

The current logic in `js_to_json` tries to rewrite octal/hex numbers to
decimal. However, when the logic actually happens the `"` or `'` have
already been trimmed off. This causes what were originally strings, that
happen to look like octal/hex numbers, to get rewritten to decimal and
returned as a number rather than a string.

In practive something like:

```js
{
  "0x40": "foo",
  "040": "bar",
}
```

would get rewritten as:

```json
{
  64: "foo",
  32: "bar
}
```

This is problematic since this isn't valid JSON as you cannot have
non-string keys.
test/test_utils.py
youtube_dl/utils.py