Git Product home page Git Product logo

Comments (5)

damog avatar damog commented on August 11, 2024

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.

hwo411 avatar hwo411 commented on August 11, 2024

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.

damog avatar damog commented on August 11, 2024

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.

hwo411 avatar hwo411 commented on August 11, 2024

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.

damog avatar damog commented on August 11, 2024

Sure, happy to receive your patch and merge it whenever you have it ready.

from feedbag.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.