Skip to content
  • Kevin O'Connor's avatar
    [utils] Don't attempt to coerce JS strings to numbers in js_to_json (#26851) · 4eda1049
    Kevin O'Connor authored
    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.
    4eda1049