aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-09-02 13:19:58 +0200
committerGravatar GitHub <noreply@github.com> 2018-09-02 13:19:58 +0200
commit32d9c3b7905f4e43ffdf4bf2bf37723cfd18390c (patch)
treec2ed9eb08533ae795b1b97718223c6bb614a18e3 /app/Models
parent565e34f7bdcc35d946d10a1840f36f40c6804f62 (diff)
Use mb_strcut (#1996)
* Use mb_strcut Avoid cutting in the middle of a multi-byte UTF-8 character * Forgotten php5-* * Typo * Whitespace * More mb_strcut
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Category.php2
-rw-r--r--app/Models/CategoryDAO.php2
-rw-r--r--app/Models/Entry.php5
-rw-r--r--app/Models/EntryDAO.php12
-rw-r--r--app/Models/FeedDAO.php4
5 files changed, 13 insertions, 12 deletions
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 9a44a2d09..197faf942 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -68,7 +68,7 @@ class FreshRSS_Category extends Minz_Model {
$this->id = $value;
}
public function _name($value) {
- $this->name = substr(trim($value), 0, 255);
+ $this->name = mb_strcut(trim($value), 0, 255, 'UTF-8');
}
public function _feeds($values) {
if (!is_array($values)) {
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index ef2c402a0..cf6b3bae3 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -9,7 +9,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable
$stm = $this->bd->prepare($sql);
$values = array(
- substr($valuesTmp['name'], 0, 255),
+ mb_strcut($valuesTmp['name'], 0, 255, 'UTF-8'),
);
if ($stm && $stm->execute($values)) {
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index 2b6059638..ccbad5724 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -31,6 +31,7 @@ class FreshRSS_Entry extends Minz_Model {
$this->_isRead($is_read);
$this->_isFavorite($is_favorite);
$this->_feedId($feedId);
+ $tags = mb_strcut($tags, 0, 1023, 'UTF-8');
$this->_tags(preg_split('/[\s#]/', $tags));
$this->_guid($guid);
}
@@ -123,11 +124,11 @@ class FreshRSS_Entry extends Minz_Model {
}
public function _title($value) {
$this->hash = null;
- $this->title = $value;
+ $this->title = mb_strcut($value, 0, 255, 'UTF-8');
}
public function _author($value) {
$this->hash = null;
- $this->author = $value;
+ $this->author = mb_strcut($value, 0, 255, 'UTF-8');
}
public function _content($value) {
$this->hash = null;
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 59f826c3e..73651187f 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -160,9 +160,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$valuesTmp['guid'] = substr($valuesTmp['guid'], 0, 760);
$valuesTmp['guid'] = safe_ascii($valuesTmp['guid']);
$this->addEntryPrepared->bindParam(':guid', $valuesTmp['guid']);
- $valuesTmp['title'] = substr($valuesTmp['title'], 0, 255);
+ $valuesTmp['title'] = mb_strcut($valuesTmp['title'], 0, 255, 'UTF-8');
$this->addEntryPrepared->bindParam(':title', $valuesTmp['title']);
- $valuesTmp['author'] = substr($valuesTmp['author'], 0, 255);
+ $valuesTmp['author'] = mb_strcut($valuesTmp['author'], 0, 255, 'UTF-8');
$this->addEntryPrepared->bindParam(':author', $valuesTmp['author']);
$this->addEntryPrepared->bindParam(':content', $valuesTmp['content']);
$valuesTmp['link'] = substr($valuesTmp['link'], 0, 1023);
@@ -176,7 +176,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$valuesTmp['is_favorite'] = $valuesTmp['is_favorite'] ? 1 : 0;
$this->addEntryPrepared->bindParam(':is_favorite', $valuesTmp['is_favorite'], PDO::PARAM_INT);
$this->addEntryPrepared->bindParam(':id_feed', $valuesTmp['id_feed'], PDO::PARAM_INT);
- $valuesTmp['tags'] = substr($valuesTmp['tags'], 0, 1023);
+ $valuesTmp['tags'] = mb_strcut($valuesTmp['tags'], 0, 1023, 'UTF-8');
$this->addEntryPrepared->bindParam(':tags', $valuesTmp['tags']);
if ($this->hasNativeHex()) {
@@ -243,9 +243,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$valuesTmp['guid'] = substr($valuesTmp['guid'], 0, 760);
$this->updateEntryPrepared->bindParam(':guid', $valuesTmp['guid']);
- $valuesTmp['title'] = substr($valuesTmp['title'], 0, 255);
+ $valuesTmp['title'] = mb_strcut($valuesTmp['title'], 0, 255, 'UTF-8');
$this->updateEntryPrepared->bindParam(':title', $valuesTmp['title']);
- $valuesTmp['author'] = substr($valuesTmp['author'], 0, 255);
+ $valuesTmp['author'] = mb_strcut($valuesTmp['author'], 0, 255, 'UTF-8');
$this->updateEntryPrepared->bindParam(':author', $valuesTmp['author']);
$this->updateEntryPrepared->bindParam(':content', $valuesTmp['content']);
$valuesTmp['link'] = substr($valuesTmp['link'], 0, 1023);
@@ -258,7 +258,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$this->updateEntryPrepared->bindValue(':is_read', $valuesTmp['is_read'] ? 1 : 0, PDO::PARAM_INT);
}
$this->updateEntryPrepared->bindParam(':id_feed', $valuesTmp['id_feed'], PDO::PARAM_INT);
- $valuesTmp['tags'] = substr($valuesTmp['tags'], 0, 1023);
+ $valuesTmp['tags'] = mb_strcut($valuesTmp['tags'], 0, 1023, 'UTF-8');
$this->updateEntryPrepared->bindParam(':tags', $valuesTmp['tags']);
if ($this->hasNativeHex()) {
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 9d980c139..285f17193 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -55,9 +55,9 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$values = array(
substr($valuesTmp['url'], 0, 511),
$valuesTmp['category'],
- substr($valuesTmp['name'], 0, 255),
+ mb_strcut($valuesTmp['name'], 0, 255, 'UTF-8'),
substr($valuesTmp['website'], 0, 255),
- substr($valuesTmp['description'], 0, 1023),
+ mb_strcut($valuesTmp['description'], 0, 1023, 'UTF-8'),
$valuesTmp['lastUpdate'],
base64_encode($valuesTmp['httpAuth']),
FreshRSS_Feed::KEEP_HISTORY_DEFAULT,