4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-13 12:46:41 +00:00

Improve native Unicode handling

- Loosen up escaping methods when uploading files via the media manager, so Unicode is preserved
 - No longer escape Unicode when outputting via JSON for API responses
This commit is contained in:
Buster "Silver Eagle" Neece 2020-12-29 15:27:39 -06:00
parent efaf75442f
commit 0acefe8321
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
3 changed files with 13 additions and 17 deletions

View File

@ -415,7 +415,7 @@ class Station
$this->name = $this->truncateString($name, 100);
if (empty($this->short_name) && !empty($name)) {
$this->setShortName($name);
$this->setShortName(null);
}
}
@ -426,13 +426,15 @@ class Station
: self::getStationShortName($this->name);
}
public function setShortName(?string $short_name): void
public function setShortName(?string $shortName): void
{
$short_name = trim($short_name);
if (!empty($short_name)) {
$short_name = self::getStationShortName($short_name);
$this->short_name = $this->truncateString($short_name, 100);
$shortName = trim($shortName);
if (empty($shortName)) {
$shortName = $this->name;
}
$shortName = self::getStationShortName($shortName);
$this->short_name = $this->truncateString($shortName, 100);
}
public static function getStationShortName(string $str): string

View File

@ -68,6 +68,7 @@ final class Response extends \Slim\Http\Response
public function withJson($data, ?int $status = null, int $options = 0, int $depth = 512): ResponseInterface
{
$options |= JSON_UNESCAPED_SLASHES;
$options |= JSON_UNESCAPED_UNICODE;
return parent::withJson($data, $status, $options, $depth);
}

View File

@ -33,19 +33,12 @@ class File
*
* @param string $str
*/
public static function sanitizeFileName($str): string
public static function sanitizeFileName(string $str): string
{
$str = strip_tags($str);
$str = preg_replace('/[\r\n\t ]+/', ' ', $str);
$str = preg_replace('/[\"\*\/\:\<\>\?\'\|]+/', ' ', $str);
$str = strtolower($str);
$str = html_entity_decode($str, ENT_QUOTES, "utf-8");
$str = htmlentities($str, ENT_QUOTES, "utf-8");
$str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
$str = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $str);
$str = mb_ereg_replace("([\.]{2,})", '.', $str);
$str = str_replace(' ', '_', $str);
$str = rawurlencode($str);
$str = str_replace('%', '-', $str);
return $str;
return mb_strtolower($str);
}
public static function generateTempPath(string $pattern = ''): string