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
Update NOTICE in libphutil

Summary: See D9730.

Test Plan: reading

Reviewers: chad

Reviewed By: chad

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D9732
Add classes to Remarkup lists and headers

Summary:
Ref T5497. We have some Remarkup CSS rules like `.remarkup ul`, which are bleeding into ObjectLists inside `{Wxxx}` and similar.

Add explicit classes to headers and lists so we can scope the Remarkup rules more tightly.

Test Plan: This stuff is covered by a million billion unit tests.

Reviewers: chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T5497

Differential Revision: https://secure.phabricator.com/D9756
Support BitBucket as an auth provider

Summary: Ref T4251. See D9760, which fixes the root issue. See D9202 for discussion.

Test Plan: Authenticated with BitBucket.

Reviewers: btrahan, asherkin

Reviewed By: asherkin

Subscribers: epriestley

Maniphest Tasks: T4251

Differential Revision: https://secure.phabricator.com/D9761
Test cases should extend from `PhutilTestCase`

Summary: Currently, a few test cases in rPHU extend from `ArcanistPhutilTestCase` instead of `PhutilTestCase`.

Test Plan: This is a really minor change, but the unit tests still pass of course.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

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