Skip to content

Commit

Permalink
fix(Db\Bookmark): Fix UTF-8 encoding ofuser-facing content
Browse files Browse the repository at this point in the history
see #2203

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Aug 5, 2024
1 parent c6e572a commit 5d3bd67
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/Db/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
* @method int getArchivedFile()
* @method setArchivedFile(int $fileId)
* @method string getTextContent()
* @method setTextContent(string $content)
* @method string getHtmlContent()
* @method setHtmlContent(string $content)
* @method string getUserId()
* @method setUserId(string $userId)
*/
Expand Down Expand Up @@ -110,6 +108,8 @@ public function setTitle(string $title): void {
if (strlen($title) > 1024) {
$title = substr($title, 0, 1020) . '';
}
// Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string
$title = mb_convert_encoding($title, 'UTF-8', 'UTF-8');
$this->setter('title', [$title]);
}

Expand All @@ -118,9 +118,37 @@ public function setDescription(string $desc): void {
if (strlen($desc) > 1024) {
$desc = substr($desc, 0, 1020) . '';
}
// Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string
$desc = mb_convert_encoding($desc, 'UTF-8', 'UTF-8');
$this->setter('description', [$desc]);
}

public function setTextContent(?string $content): void {
if ($content === null) {
// Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string
$content = mb_convert_encoding($content, 'UTF-8', 'UTF-8');
}
$this->setter('textContent', [$content]);
}

public function getTextContent(): string {
// Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string
return mb_convert_encoding($this->textContent, 'UTF-8', 'UTF-8');
}

public function setHtmlContent(?string $content): void {
if ($content === null) {
// Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string
$content = mb_convert_encoding($content, 'UTF-8', 'UTF-8');
}
$this->setter('htmlContent', [$content]);
}

public function getHtmlContent(): string {
// Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string
return mb_convert_encoding($this->htmlContent, 'UTF-8', 'UTF-8');
}

public function isWebLink() {
return (bool) preg_match('/^https?:/i', $this->getUrl());
}
Expand Down

0 comments on commit 5d3bd67

Please sign in to comment.