Skip to content

Commit

Permalink
Merge pull request #46779 from nextcloud/fix/testing/textprocessing-u…
Browse files Browse the repository at this point in the history
…nicode

fix(testing): Make Testing TextProcessing providers unicode safe
  • Loading branch information
marcelklehr authored Jul 27, 2024
2 parents 0ae83d6 + b9187dc commit 5639d99
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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));
}
}

0 comments on commit 5639d99

Please sign in to comment.