Skip to content

Commit

Permalink
Fix hashKey for unicode texts
Browse files Browse the repository at this point in the history
  • Loading branch information
richardDobron committed Jun 16, 2023
1 parent 33c744f commit ecc3e3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/fbt/Transform/FbtTransform/fbtHash.php
Expand Up @@ -44,7 +44,7 @@ public static function fbtJenkinsHash($jsfbt, $desc, $noStringify = false): int
is_string($payload),
'JSFBT is not a string type. Please disable noStringify'
);
$key = $payload . '|' . $desc;
$key = utf8_encode($payload . '|' . $desc);

return self::jenkinsHash($key);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/fbt/fbtTest.php
Expand Up @@ -10,6 +10,7 @@
use fbt\Lib\IntlViewerContext;
use fbt\Runtime\Shared\fbt;
use fbt\Runtime\Shared\FbtHooks;
use fbt\Transform\FbtRuntime\FbtRuntimeTransform;
use fbt\Transform\FbtTransform\FbtTransform;
use fbt\Transform\FbtTransform\Translate\IntlVariations;

Expand Down Expand Up @@ -601,6 +602,16 @@ public function testNumberLiteralValueAsIs()
$this->assertSame('A total amount is 10000', self::transform($fbt));
}

public function testUnicodeText()
{
$fbt = (string)fbt('Pick an emoji…', 'placeholder text for emoji picker');

$hashKey = FbtRuntimeTransform::transform(FbtTransform::$phrases[0])['hk'];

$this->assertSame('ZAVir', $hashKey);
$this->assertSame('Pick an emoji…', $fbt);
}

public function testHtmlBreak()
{
$fbt = <<<FBT
Expand Down

0 comments on commit ecc3e3b

Please sign in to comment.