Parse HHBC option as bool only if it's a flag
commitc9a452c73eca20f45349f816bf4fd96627438d95
authorLeo Osvald <leoo@fb.com>
Thu, 5 Mar 2020 23:42:18 +0000 (5 15:42 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 6 Mar 2020 00:16:30 +0000 (5 16:16 -0800)
tree172b5e28d71f91530dc5126e3a619528d9b7c879
parentffa091383416982886e54b72207dee76aebf44b4
Parse HHBC option as bool only if it's a flag

Summary:
The JSON config passed to hh_single_compile by HHVM contains a
**superset** of HHBC-relevant config, e.g.:

  { ...
    "hhvm.trusted_db_path": {
       "access": 4,
       "local_value": "",
       "global_value": "" }
  }

Therefore, skip the interpretation of such an option as flag in Rust
**until *after*** it's determined that it indeed represents a flag.
Now, unrelated HHVM options with values such as:

- "" (empty string); or
- "12345678901234567890" (integer-overflowing constant)

no longer panic / make the whole JSON parse to fail
(as a result of parsing a non-int/bool-convertible string).

Add regression tests for these two cases.

Finally, treat empty string values as false for flags as in OCaml code.

Reviewed By: dabek

Differential Revision: D20265758

fbshipit-source-id: 74cac1d8a718c35a06a804aee5f9a97268f3ef30
hphp/hack/src/hhbc/options.rs