From 34342814a0e66764e36f815d23479f1735f146fc Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 15 Apr 2013 18:49:44 +0200 Subject: [PATCH] fix potential errors when fetching favicon that preven feed from being added, fix #66 by not shortening the url --- .../businesslayer/feedbusinesslayer.coffee | 4 +--- js/public/app.js | 2 +- .../businesslayer/feedbusinesslayerSpec.coffee | 17 +---------------- utility/feedfetcher.php | 13 ++++++++++++- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/js/app/services/businesslayer/feedbusinesslayer.coffee b/js/app/services/businesslayer/feedbusinesslayer.coffee index d83e38268..fcdcc8093 100644 --- a/js/app/services/businesslayer/feedbusinesslayer.coffee +++ b/js/app/services/businesslayer/feedbusinesslayer.coffee @@ -140,9 +140,7 @@ FeedModel, NewLoading, _ExistsError, Utils) -> throw new _ExistsError('Exists already') feed = - title: url.replace( - /^(?:https?:\/\/)?(?:www\.)?([a-z0-9_\-\.]+)(?:\/.*)?$/gi, - '$1') + title: url url: url urlHash: urlHash folderId: parentId diff --git a/js/public/app.js b/js/public/app.js index 02fc9c32c..c76a338ee 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -896,7 +896,7 @@ License along with this library. If not, see . throw new _ExistsError('Exists already'); } feed = { - title: url.replace(/^(?:https?:\/\/)?(?:www\.)?([a-z0-9_\-\.]+)(?:\/.*)?$/gi, '$1'), + title: url, url: url, urlHash: urlHash, folderId: parentId, diff --git a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee index 1ee9aaa3d..476d74d30 100644 --- a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee @@ -255,28 +255,13 @@ describe 'FeedBusinessLayer', -> feed = @FeedModel.getByUrlHash(hash) - expect(feed.title).toBe('google.de') + expect(feed.title).toBe('www.google.de') expect(feed.url).toBe(url) expect(feed.urlHash).toBe(hash) expect(feed.folderId).toBe(0) expect(feed.unreadCount).toBe(0) expect(@imagePath).toHaveBeenCalledWith('core', 'loading.gif') - it 'should transform urls correctly', => - urls = [ - 'www.google.de' - 'www.google.de/' - 'google.de' - 'http://google.de' - 'http://www.google.de/' - ] - for url in urls - @FeedModel.clear() - @FeedBusinessLayer.create(url) - hash = hex_md5(url) - feed = @FeedModel.getByUrlHash(hash) - expect(feed.title).toBe('google.de') - it 'should make a create feed request', => @persistence.createFeed = jasmine.createSpy('add feed') diff --git a/utility/feedfetcher.php b/utility/feedfetcher.php index 4b91865f5..1f67d328e 100644 --- a/utility/feedfetcher.php +++ b/utility/feedfetcher.php @@ -204,7 +204,18 @@ class FeedFetcher implements IFeedFetcher { // try the /favicon.ico as a last resort $parseUrl = parse_url($url); - $baseFavicon = $parseUrl['scheme'] . '://' . $parseUrl['host'] . '/favicon.ico'; + if (!array_key_exists('scheme', $parseUrl)){ + $scheme = 'http'; + } else { + $scheme = $parseUrl['scheme']; + } + + if(!array_key_exists('host', $parseUrl)){ + error_log($url); + return null; + } + + $baseFavicon = $scheme . '://' . $parseUrl['host'] . '/favicon.ico'; if($this->isValidFavIcon($baseFavicon)){ return $baseFavicon; }