Add AWS Region support to PhutilAWSFuture.

Summary:
Almost [[http://docs.aws.amazon.com/general/latest/gr/rande.html|all]] AWS services endpoints follow this structure: `SERVICE_NAME.REGION_ID.amazonaws.com`. This revision adds support for setting a region in `PhutilAWSFuture`.

There are couple of exceptions to above rule - some services do not have region in their endpoint url (DevPay, Route 53, IAM, Import/Export, Security Token Service), some have a single endpoint in one region (OpsWorks, Support), some are //funky// (S3), but they all can be covered by overriding `getHost()` method.

Test Plan: No tests added. I `ack`ed through three repositories (`libphutil`, `arcanist` & `phabricator`) and couldn't find AWS used anywhere.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D8311
Add phutil_is_utf8_with_only_bmp_characters()

Summary:
Ref T1191. We currently use `utf8` charsets in MySQL, which silently truncate characters outside of the basic multilingual plane (larger than U+FFFF) like "Musical G-Clef".

Add a method to detect that a string contains characters outside of this range, and thus that inserting it will silently truncate data.

Test Plan: Added and executed unit tests.

Reviewers: btrahan, arice

Reviewed By: arice

CC: chad, arice, aran

Maniphest Tasks: T1191

Differential Revision: https://secure.phabricator.com/D8310
Implement phutil_is_utf8_with_only_bmp_characters() without segfaulting

Summary: See comments. The regexp based implementation segfaults unpreventably on small inputs. Do it nice and slow in PHP instead.

Test Plan: Ran unit tests.

Reviewers: btrahan, arice

Reviewed By: arice

CC: chad, arice, aran

Differential Revision: https://secure.phabricator.com/D8312
Reject nonminmal representations of UTF8 at the beginning of the 3-byte BMP range

Summary: Ref T1191. These byte ranges (\xE0\x80\x80 through \xE0\x9F\xBF) are alternate representations of characters with a different preferred minimal representation. MySQL and mbstring both reject them, and we should too.

Test Plan: Ran unit tests.

Reviewers: btrahan, arice

Reviewed By: arice

CC: chad, arice, aran

Maniphest Tasks: T1191

Differential Revision: https://secure.phabricator.com/D8313
Change "%s" in qsprintf to exclude non-BMP characters

Summary:
Ref T1191. Make `%s` in qsprintf reject non-BMP characters. Introduce `%B` for escaping binary strings.

Basically, this just makes "yes, I want to put binary data in this column" explicit.

Test Plan: See next diff for test coverage in Phabricator.

Reviewers: btrahan, arice

Reviewed By: arice

CC: chad, arice, aran

Maniphest Tasks: T1191

Differential Revision: https://secure.phabricator.com/D8315
Remove "supportsStateParameter()" from generic OAuth2 code

Summary:
Depends on D8318. All providers must support this, or they can't be implemented securely. This is based on a very old reading of the GitHub instructions or something like that which didn't mention "state", but the provider supports it.

This has no impact at runtime because no provider has ever returned `false` from this method, nor would we ever implement a provider that did.

Test Plan: Grepped for callsites.

Reviewers: btrahan, arice

Reviewed By: arice

CC: chad, arice, aran

Differential Revision: https://secure.phabricator.com/D8319
Fix phutil_is_utf8_with_only_bmp_characters() for partial valid characters

Summary:
We don't get partial 2-byte and 3-byte UTF8 characters quite correct, fataling instead of returning `false` because we access past the end of the string.

Instead, bail early if we run off the end of the string without seeing any issues.

Test Plan: Added and executed unit tests.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D8321
Updated `.arcconfig` to match newer style configuration.

Summary: If I'm not mistaken, `project_id` was recently replaced by `project.name` and `conduit_uri` replaced by `phabricator.uri`.

Test Plan: I guess if this differential works, then everything is okay.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D8334
Minor linter fixes

Summary:
Fixed various linter issues that were identified with `arc lint --everything`.

- Changed tabs to spaces.
- Removed trailing newlines.
- Added whitespace on either side of binary operator.
- Added newline at EOF.
- Minor spelling fix.
- Removed leading newlines.

Test Plan: N/A

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D8335
Made the `AphrontWriteGuardExitEventListener` class final.

Summary: Self explanatory... Otherwise a linter warning is raised.

Test Plan: N/A

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D8350
Add phutil_json_decode(), for convenience

Summary:
This is just a convenience method for decoding possibly-sketchy strings. We have a lot of cases where we may try to decode some uninitialized value (like `null`) and then check if we got something sensible out or not.

Particularly, almost all of these can likely be simplified:

  $ git grep -A1 -i 'json_decode' . | grep is_array | wc -l
  33

Test Plan: Added and executed unit tests.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D8363
Generate a reasonable Diviner book from libphutil

Summary: Ref T988. This isn't pretty or polished, but it has the documentation.

Test Plan: Generated and read the documentation.

Reviewers: chad, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T988

Differential Revision: https://secure.phabricator.com/D8412
Add assertions to every test in libphutil/

Summary: Ref T4570. Add an assertion to all tests which pass by not exploding, so we can fail tests which make no assertions.

Test Plan: `arc unit --everything` with the test engine set to fail on no assertions.

Reviewers: leebyron, btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4570

Differential Revision: https://secure.phabricator.com/D8435
Utilize `assertFalse` and `assertTrue` methods.

Summary:
Ref D8460.

Use $this->assertFalse(...) and $this->assertTrue(...) instead of $this->assertEqual(false, ...) and $this->assertEqual(true, ...) respectively.

Test Plan: `arc unit`

Reviewers: epriestley, #blessed_reviewers

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D8462
Update some libphutil docs

Summary: Improve organization and content of some documentation.

Test Plan: Regenerated and examined docs.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D8479
Don't format "1/" as an ordered list in Remarkup

Summary: See <https://www.facebook.com/dreiss/posts/10152231659206208>. I added this "bizarre Facebook-ism" to the set of ordered list characters in T3797, but apparently the intent of these "1/" lists is to avoid automatic formatting. I don't fully understand any part of this, but this list style is used only at Facebook, and automatically formatting these lists enjoys little support there (25 against, 2 for, 29 neutral).

Test Plan: Updated and executed unit tests.

Reviewers: btrahan, chad, dreiss

Reviewed By: dreiss

Subscribers: aran, epriestley

Differential Revision: https://secure.phabricator.com/D8489
Censor URI credentials in CommandException summaries

Summary:
Fixes T4347. Make a simple effort to mask credentials (e.g., arising from stderr on `git fetch`) when formatting command failures for user consumption.

This isn't perfect, but I think it's a net positive overall.

Test Plan:
Added and executed unit tests. Also triggered a real exception:

  EXCEPTION (CommandException): Command failed with error #1!
  COMMAND
  echo 'http://xxxxx@example.com' && false

  STDOUT
  http://xxxxx@example.com

  STDERR
  (empty)

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4347

Differential Revision: https://secure.phabricator.com/D8546
Filter "javascript:" URIs more aggressively

Summary: Some browsers interpret `javascript\n:` as a Javascript URI. Be significantly more aggressive in normalizing URIs when looking for `javascript:` hrefs.

Test Plan: Added and executed unit tests.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D8548
Allow multiple LDAP search filters, and complex search queries

Summary: Ref T3208. I'm going to make some people try this before it gets anywhere near landing.

Test Plan: oh man LDAP

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley, frgtn, aran

Maniphest Tasks: T3208

Differential Revision: https://secure.phabricator.com/D8159
Pass an integer to stream_select() for correctness

Summary: Ref T4627. Passing `$timeout_sec` is slightly more correct here, although there is no change to program behavior.

Test Plan:
Used this script to verify that passing `0` and `0.999321` (for example) have the same effect to `stream_select()`:

  <?php

  $spec = array(
    0 => array('pipe', 'r'),
    1 => array('pipe', 'w'),
    2 => array('pipe', 'w'),
  );

  $pipes = array();
  $proc = proc_open('sleep 30', $spec, $pipes);
  list($stdin, $stdout, $stderr) = $pipes;

  $read = array($stdout, $stderr);
  $write = array();
  $except = array();

  $select_start = microtime(true);
  stream_select($read, $write, $except, 0.999321, 80000);
  $select_end = microtime(true);

  printf(
    "select() took %d us to return.\n",
    ($select_end - $select_start) * 1000000);

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4627

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