HH\Lib\Legacy_FIXME\coerce_possibly_invalid_str_replace_pairs

Fix invalid inputs to Str\replace_every and similar functions

namespace HH\Lib\Legacy_FIXME;

function coerce_possibly_invalid_str_replace_pairs(
  KeyedContainer<string, string> $pairs,
): dict<string, string>;

Replacement pairs are required to be a string-to-string map, where the key is a non-empty string (as find-replace for the empty string doesn't make sense).

Previously, these requirements were not consistently enforced; the HSL would sometimes raise an error, but sometimes would coerce to string, and silently drop empty string keys.

Non-string keys/values required a FIXME.

This function is intended to be used like so:

$out = Str\replace_every( $in, Legacy_FIXME\coerce_possibly_invalid_str_replace_pairs($replacements) );

Calls to this function should be removed when safe to do so.

Parameters

Returns

  • dict<string, string>