A free, self-hostable news aggregator…
API encoding tuning (#2120)
Alexandre Alapetite0fce9892ff2b
diff --git a/app/Models/Feed.php b/app/Models/Feed.phpindex a5ef33d6b..acf3bd981 100644--- a/app/Models/Feed.php+++ b/app/Models/Feed.php@@ -424,7 +424,7 @@ class FreshRSS_Feed extends Minz_Model {$author_names = '';if (is_array($authors)) {foreach ($authors as $author) {- $author_names .= escapeToUnicodeAlternative(strip_tags($author->name == '' ? $author->email : $author->name)) . '; ';+ $author_names .= escapeToUnicodeAlternative(strip_tags($author->name == '' ? $author->email : $author->name), true) . '; ';}}$author_names = substr($author_names, 0, -2);diff --git a/lib/lib_rss.php b/lib/lib_rss.phpindex 52e4408d2..c445874c8 100644--- a/lib/lib_rss.php+++ b/lib/lib_rss.php@@ -102,16 +102,21 @@ function safe_ascii($text) {return filter_var($text, FILTER_DEFAULT, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);}-function escapeToUnicodeAlternative($text) {+function escapeToUnicodeAlternative($text, $extended = true) {$text = htmlspecialchars_decode($text, ENT_QUOTES);++ //Problematic characters+ $problem = array('&', '<', '>');+ //Use their fullwidth Unicode form instead:+ $replace = array('&', '<', '>');+// https://raw.githubusercontent.com/mihaip/google-reader-api/master/wiki/StreamId.wiki- return trim(str_replace(- //Problematic characters- array("'", '"', '^', '<', '>', '?', '&', '\\', '/', ',', ';'),- //Use their fullwidth Unicode form instead:- array("’", '"', '^', '<', '>', '?', '&', '\', '/', ',', ';'),- $text- ));+ if ($extended) {+ $problem += array("'", '"', '^', '?', '\\', '/', ',', ';');+ $replace += array("’", '"', '^', '?', '\', '/', ',', ';');+ }++ return trim(str_replace($problem, $replace, $text));}/**diff --git a/p/api/greader.php b/p/api/greader.phpindex 7c5c54951..7cd312f2c 100644--- a/p/api/greader.php+++ b/p/api/greader.php@@ -300,7 +300,7 @@ function subscriptionList() {foreach ($res as $line) {$subscriptions[] = array('id' => 'feed/' . $line['id'],- 'title' => escapeToUnicodeAlternative($line['name']),+ 'title' => escapeToUnicodeAlternative($line['name'], true),'categories' => array(array('id' => 'user/-/label/' . htmlspecialchars_decode($line['c_name'], ENT_QUOTES),@@ -506,7 +506,7 @@ function entriesToArray($entries) {'crawlTimeMsec' => substr($entry->id(), 0, -3),'timestampUsec' => '' . $entry->id(), //EasyRSS'published' => $entry->date(true),- 'title' => escapeToUnicodeAlternative($entry->title()),+ 'title' => escapeToUnicodeAlternative($entry->title(), false),'summary' => array('content' => $entry->content()),'alternate' => array(array('href' => htmlspecialchars_decode($entry->link(), ENT_QUOTES)),@@ -517,14 +517,14 @@ function entriesToArray($entries) {),'origin' => array('streamId' => 'feed/' . $f_id,- 'title' => escapeToUnicodeAlternative($f_name), //EasyRSS+ 'title' => escapeToUnicodeAlternative($f_name, true), //EasyRSS//'htmlUrl' => $line['f_website'],),);$author = $entry->authors(true);$author = trim($author, '; ');if ($author != '') {- $item['author'] = escapeToUnicodeAlternative($author);+ $item['author'] = escapeToUnicodeAlternative($author, false);}if ($entry->isRead()) {$item['categories'][] = 'user/-/state/com.google/read';