Contournement bug PHP 5.3.3-

Bug #51192  FILTER_VALIDATE_URL will invalidate a hostname that includes
'-'
https://bugs.php.net/bug.php?id=51192
Corrige https://github.com/marienfressinaud/FreshRSS/issues/221

Au passage, désactive la validation des URLS provenant de la base de
données et qui ont déjà été validées.
This commit is contained in:
Alexandre Alapetite committed 2013-11-06 23:21:14 +01:00
1 parent fe78c7fff3
commit ec052432c0
2 files changed
+18 -6

No files matched your search

+14 -5
View File
@@ -17,8 +17,12 @@ class Feed extends Model {
private $error = false;
private $keep_history = false;
public function __construct ($url) {
$this->_url ($url);
public function __construct ($url, $validate=true) {
if ($validate) {
$this->_url ($url);
} else {
$this->url = $url;
}
}
public function id () {
@@ -110,11 +114,16 @@ class Feed extends Model {
$this->id = $value;
}
public function _url ($value) {
if (!is_null ($value) && !preg_match ('#^https?://#', $value)) {
if (empty ($value)) {
throw new BadUrlException ($value);
}
if (!preg_match ('#^https?://#', $value)) {
$value = 'http://' . $value;
}
if (!is_null ($value) && filter_var ($value, FILTER_VALIDATE_URL)) {
if (filter_var ($value, FILTER_VALIDATE_URL)) {
$this->url = $value;
} elseif (version_compare(PHP_VERSION, '5.3.3', '<') && (strpos($value, '-') > 0) && ($value === filter_var($value, FILTER_SANITIZE_URL))) { //PHP bug #51192
$this->url = $value;
} else {
throw new BadUrlException ($value);
@@ -527,7 +536,7 @@ class HelperFeed {
$key = $dao['id'];
}
$list[$key] = new Feed ($dao['url']);
$list[$key] = new Feed ($dao['url'], false);
$list[$key]->_category ($dao['category']);
$list[$key]->_name ($dao['name']);
$list[$key]->_website ($dao['website']);
+4 -1
View File
@@ -248,9 +248,12 @@ class RSSConfiguration extends Model {
$this->mark_when['scroll'] = $values['scroll'];
}
public function _urlShaarli ($value) {
$this->url_shaarli = '';
if (filter_var ($value, FILTER_VALIDATE_URL)) {
$this->url_shaarli = $value;
} elseif (version_compare(PHP_VERSION, '5.3.3', '<') && (strpos($value, '-') > 0) && ($value === filter_var($value, FILTER_SANITIZE_URL))) { //PHP bug #51192
$this->url_shaarli = $value;
} else {
$this->url_shaarli = '';
}
}
public function _theme ($value) {