Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(testing): Make Testing TextProcessing providers unicode safe #46779

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/testing/lib/Provider/FakeTextProcessingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ public function getName(): string {
}

public function process(string $prompt): string {
return strrev($prompt) . ' (done with FakeTextProcessingProvider)';
return $this->mb_strrev($prompt) . ' (done with FakeTextProcessingProvider)';
}

public function getTaskType(): string {
return FreePromptTaskType::class;
}

/**
* Reverse a miltibyte string.
*
* @param string $string The string to be reversed.
* @return string The reversed string
*/
private function mb_strrev(string $string): string {
$chars = mb_str_split($string, 1);
return implode('', array_reverse($chars));
}
}
13 changes: 12 additions & 1 deletion apps/testing/lib/Provider/FakeTextProcessingProviderSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getName(): string {
}

public function process(string $prompt): string {
return strrev($prompt) . ' (done with FakeTextProcessingProviderSync)';
return $this->mb_strrev($prompt) . ' (done with FakeTextProcessingProviderSync)';
}

public function getTaskType(): string {
Expand All @@ -30,4 +30,15 @@ public function getTaskType(): string {
public function getExpectedRuntime(): int {
return 1;
}

/**
* Reverse a miltibyte string.
*
* @param string $string The string to be reversed.
* @return string The reversed string
*/
private function mb_strrev(string $string): string {
$chars = mb_str_split($string, 1);
return implode('', array_reverse($chars));
}
}
Loading