Comments (5)
Yeah, this seems to be a nasty bug that the URL is uncovering because of the +
sign on the URL.
This diff may fix it:
diff --git a/lib/feedbag.rb b/lib/feedbag.rb
index b145fa3..6df550d 100644
--- a/lib/feedbag.rb
+++ b/lib/feedbag.rb
@@ -167,7 +167,7 @@ class Feedbag
end
def looks_like_feed?(url)
- if url =~ /(\.(rdf|xml|rss)(\?([\w'\-%]?(=[\w'\-%.]*)?(&|#)?)+)?(:[\w'\-%]+)?$|feed=(rss|atom)|(atom|feed)\/?$)/i
+ if url =~ /(\.(rdf|xml|rss)(\?([\w'\-%]?(=[\w'\-%.]*)?(&|#|\+)?)+)?(:[\w'\-%]+)?$|feed=(rss|atom)|(atom|feed)\/?$)/i
true
else
false
Any way you can give this a shot?
from feedbag.
Thanks @damog for quick answer! Unfortunately, it doesn't help:
url = 'https://link.springer.com/search.rss?facet-content-type=Article&facet-journal-id=41116&channel-name=Living+Reviews+in+Solar+Physics'
url =~ /(\.(rdf|xml|rss)(\?([\w'\-%]?(=[\w'\-%.]*)?(&|#|\+)?)+)?(:[\w'\-%]+)?$|feed=(rss|atom)|(atom|feed)\/?$)/i
is still slow (waited for more than 20 seconds then cancelled).
I wonder if you can check it without regexp.
E.g., by parsing url and checking if path contains rdf/xml/rss and or other conditions.
from feedbag.
You seem to be manually passing the URL to the regex. This may or may not work (it surely doesn't from your example :)). But you may be skipping the parsing that Nokogiri makes on the HTML elements of the page. I suggest you try using the library directly. With some debug statements, the provided regex work with the following URLs:
irb(main):003:0> url = 'https://link.springer.com/search.rss?facet-content-type=Article&facet-journal-id=41116&channel-name=Living+Reviews+in+Solar+Physics'
=> "https://link.springer.com/search.rss?facet-content-type=Article&facet-journal-id=41116&channel-name=Living+Reviews+in+Solar+Physics"
irb(main):004:0> url =~ /(\.(rdf|xml|rss)(\?([\w'\-%]?(=[\w'\-%.]*)?(&|#|\+)?)+)?(:[\w'\-%]+)?$|feed=(rss|atom)|(atom|feed)\/?$)/i
=> 32
irb(main):005:0> url = 'http://link.springer.com/search.rss?facet-content-type=Article&facet-journal-id=11207&channel-name=Solar%20Physics'
=> "http://link.springer.com/search.rss?facet-content-type=Article&facet-journal-id=11207&channel-name=Solar%20Physics"
irb(main):006:0> url =~ /(\.(rdf|xml|rss)(\?([\w'\-%]?(=[\w'\-%.]*)?(&|#|\+)?)+)?(:[\w'\-%]+)?$|feed=(rss|atom)|(atom|feed)\/?$)/i
=> 31
irb(main):007:0>
The next culprit seems to be the interpretation of & → &
so adding the ;
to the regex may also work. You can test this manually too:
url =~ /(\.(rdf|xml|rss)(\?([\w'\-%]?(=[\w'\-%.]*)?(&|#|\+|\;)?)+)?(:[\w'\-%]+)?$|feed=(rss|atom)|(atom|feed)\/?$)/i
I'm not committing changes just yet as these quick fixes will need further deep dive.
Let me know how it works.
dm
from feedbag.
Thanks @damog! Let me mention that the url that I used directly ( https://link.springer.com/search.rss?facet-content-type=Article&facet-journal-id=41116&channel-name=Living+Reviews+in+Solar+Physics ) was taken from debugging the feedbag, so it was after Nokogiri parsing. But I'll try to do as you suggested anyway to see if it helps in other places and get back to you.
In general, I'd rather refrain from using complex regexp in favor of clear simple checks if possible, since it'll also make the code more readable and understandable and easier to extend. Thinks like url.path.match(/\.(rdf|xml|rss)$/)
are clearly easier to debug in case of problems and even if the code becomes slower, I think that http request of fetching the feed takes much more than any set of such checks. Also, if we already know that such Regexp is slow in some cases, then at some moment one will definitely face such case even if some of the precautions are made, because we can't be sure that all precautions were made.
WDYT?
from feedbag.
Sure, happy to receive your patch and merge it whenever you have it ready.
from feedbag.
Related Issues (13)
- Unable to resolve dependency: 'feedbag (= 0.9.4)' requires 'nokogiri (~> 0)' HOT 3
- Can't discover existing feed HOT 2
- UserAgent override needed for specific feeds HOT 1
- Feedbag mistakenly tells that html page is feed HOT 2
- Possibility to specify timeout HOT 2
- Ruby 2.7 warnings HOT 1
- Add support for non-ASCII URLs
- allow overriding error output?
- URI::InvalidURIError (bad URI(is not URI?) HOT 2
- Gem is dependent on hpricot? HOT 1
- Feedbag don't find RSS from sites like Gizmodo HOT 7
- Sponsorship? HOT 19
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feedbag.