Fixing so that on windows local paths to binaries can be used

Summary: On windows, using something like "vendor/bin/phpcs" does not work because the code tries to run "where vendor/bin/phpcs" which fails badly. So instead, when we try to test for a binary on windows, we first check if a file exists locally with that name. If it does, just use that. If someone has a file in their project with the same name as a linter, but that is not the actual linter, this could fail, but I can't imagine a case where that would happen.

Test Plan: On windows, run `arc lint` with a linter configured that is local e.g. "vendor/bin/phpcs"

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9493
Pass additional arguments to the `PhabricatorDaemonEventListener`.

Summary: Include non-standard command line arguments in the `daemon.didLaunch` event.

Test Plan: See D9607.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9613
Fix failing unit test.

Summary: On PHP versions earlier than 5.4.0, `\e` is not a valid PHP escape character. Consequently, `PhutilUTF8TestCase::testUTF8ConsoleStrlen` will fail. Replace `\e` by its hexadecimal equivalent.

Test Plan: Ran unit tests.

Reviewers: hach-que, epriestley, #blessed_reviewers

Reviewed By: hach-que, epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9615
Rename `interestingArgv` to `explicitArgv`.

Summary: `interestingArgv` isn't a very useful name, see D9607#45.

Test Plan: N/A

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9617
Fix `PhutilReadableSerializer` to quote strings.

Summary: See D9622#inline-37279 for explanation.

Test Plan: Modified and ran unit tests.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9632
Add a native JSON parser.

Summary: Ref T5297. Add [[https://github.com/Seldaek/jsonlint | JsonLint]] as an external library and provide `PhutilJSONParser` as a wrapper around the library's functionality.

Test Plan: Wrote some basic unit tests and ran `arc unit`.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Maniphest Tasks: T5297

Differential Revision: https://secure.phabricator.com/D9622
Modify the JsonLint library to return `array` instead of `stdClass`.

Summary:
Summary :Ref T5297. Make `PhutilJSONParser::parse($json)` roughly approximate to `json_decode($json, true)`. Generally when we parse JSON, we want the result to be an `arrray`, not a `stdClass` object.

Depends on D9622.

Test Plan: Wrote a few additional test cases.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T5297

Differential Revision: https://secure.phabricator.com/D9623
Fix the handling of empty keys in `PhutilJSONParser`.

Summary:
Because the empty string is not a valid property of `stdClass`, the original [[https://github.com/Seldaek/jsonlint | JsonLint]] library replaced empty keys with `'_empty_'`. After D9623, all instances of `stdClass` have been replaced by arrays, so we can remove this nonsense.

Depends on D9623.

Test Plan: Added a test case and ran `arc unit`.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9633
Throw better exceptions from `PhutilJSONParser`.

Summary:
Ref T5297. Retrieve error context from `JsonLintParsingException` to provide a better exception message.

Depends on D9623.

Test Plan: Wrote and executed unit tests.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Maniphest Tasks: T5297

Differential Revision: https://secure.phabricator.com/D9624
Add an optional mode for `PhutilJSONParser` to detect duplicate keys

Summary:
Ref T5297. Change `PhutilJSONParser` to disallow duplicate keys by default. In addition, add an optional mode to //allow// duplicate keys. One important caveat here is that `PhutilJSONParser` will return the //first// value in the case of a duplicate, whereas `json_decode` will return the last value.

Depends on D9624.

Test Plan: Wrote and executed unit tests.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T5297

Differential Revision: https://secure.phabricator.com/D9627
Minor fix for `JsonLintJsonLinter` class.

Summary: Remove a `\` character, which will probably cause issues on PHP versions earlier than 5.3.

Test Plan: Thought long and hard.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9636
Add more unit tests for `PhutilJSONParser`.

Summary: Added some additional unit tests taken from the [[https://github.com/Seldaek/jsonlint | original source]].

Test Plan: Ran `arc unit`.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9638
Modify `phutil_json_decode` to use `PhutilJSONParser`.

Summary: Ref T5297. Modify `phutil_json_decode` to use `PhutilJSONParser` instead of the native `json_decode`.

Test Plan: Ran `arc unit`.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T5297

Differential Revision: https://secure.phabricator.com/D9634
Update callsites of `phutil_json_decode`.

Summary: Depends on D9634. `phutil_json_decode` now throws an exception on invalid JSON.

Test Plan: Not really sure how to test this?

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9639
Provide more flexible string truncation in libphutil

Summary:
Ref T3307. We sometimes need to truncate strings to a given length for display, storage, or for other reasons.

Currently, `phutil_utf8_shorten()` can do this for display, but because it handles combining characters it doesn't actually impose any storage limits on the result: if the input is `o` and 50 megabytes of combining umlauts, the output will be the same as the input, since this is only "1 display character" long.

Instead, allow truncation to specify maximum byte, codepoint (utf8 character) and glyph (display character) limits.

Test Plan: Added more unit tests.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3307

Differential Revision: https://secure.phabricator.com/D9368
Fall back to slow UTF8 algorithms that don't crash

Summary:
Fixes T5316. PCRE can blow stacks on `(x|y)+` regexps, and a user is hitting a consistent fatal in PCRE.

Rewrite the fallback for `phutil_is_utf8()` to be iterative. This is somewhat slower, but not normally too horrible, and we have a variety of ways to mitigate that if it arises as a real issue (encourage installation of mb extension, ship a fast C extension, etc).

We already have most of this code anyway.

Test Plan: We have fairly good test coverage here already, I mostly just realigned the existing test coverage to explicitly call the new code.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: webframp, epriestley

Maniphest Tasks: T5316

Differential Revision: https://secure.phabricator.com/D9472
Lint JSON files with `ArcanistJSONLinter`.

Summary: After D9628, we can lint JSON files natively.

Test Plan: See D9652.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9653
Update library map for `phutil_is_utf8_slowly`.

Summary: It appears that `arc liberate` wasn't run for D9472.

Test Plan: Meh...

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9665
Minor whitespace changes.

Summary:
A few minor whitespace changes:

- Change tabs to spaces.
- Don't change tabs to spaces in test cases.
- Don't apply `.editorconfig` rules to the `externals` directory.

Test Plan: N/A

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9673
Improve the exception message for JSON parsing exceptions.

Summary: Provide contextual information relating to JSON parser exceptions.

Test Plan: See D9679.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9680