aboutsummaryrefslogtreecommitdiff
path: root/lib/lib_rss.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2015-04-05 12:41:16 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2015-04-05 12:41:16 +0200
commit2d18910d02d92098257b96766e5b89a780daab0b (patch)
tree3253e5c42fe974401454c16cdb14e926550375ca /lib/lib_rss.php
parent2a0d04dd0ec7f7a453cf15ef7846bca662335050 (diff)
Support for Internationalized Domain Names (IDN)
https://github.com/FreshRSS/FreshRSS/issues/819 Add explicit conversion from IDN to Punycode. Requires PHP 5.3 IDN extension http://php.net/intl.idn (php5-idn package on Debian/Ubuntu). For systems without PHP 5.3+ IDN extension, we may consider adding a dependency (322 kB) to the third-party library https://phlymail.com/en/downloads/idna-convert.html See PHP bug 53474 FILTER_VALIDATE_URL should not fail URL's that use IDNhttps://bugs.php.net/bug.php?id=53474
Diffstat (limited to 'lib/lib_rss.php')
-rw-r--r--lib/lib_rss.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index e5fe73041..bc5d6fc5b 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -51,6 +51,21 @@ function classAutoloader($class) {
spl_autoload_register('classAutoloader');
//</Auto-loading>
+function idn_to_punny($url) {
+ if (function_exists('idn_to_ascii')) {
+ $parts = parse_url($url);
+ if (!empty($parts['host'])) {
+ $idn = $parts['host'];
+ $punny = idn_to_ascii($idn);
+ $pos = strpos($url, $idn);
+ if ($pos !== false) {
+ return substr_replace($url, $punny, $pos, strlen($idn));
+ }
+ }
+ }
+ return $url;
+}
+
function checkUrl($url) {
if (empty ($url)) {
return '';
@@ -58,6 +73,7 @@ function checkUrl($url) {
if (!preg_match ('#^https?://#i', $url)) {
$url = 'http://' . $url;
}
+ $url = idn_to_punny($url); //PHP bug #53474 IDN
if (filter_var($url, FILTER_VALIDATE_URL) ||
(version_compare(PHP_VERSION, '5.3.3', '<') && (strpos($url, '-') > 0) && //PHP bug #51192
($url === filter_var($url, FILTER_SANITIZE_URL)))) {