csquared/IMGKit — Issue #11: Source#url? returns true erroneously
Author: cboone
Created: 2012-02-01 18:50:17+00:00
State: open

The regular expression that `Source#url?` uses to determine if the `url_file_or_html` is a URL returns true if any line in the passed in string starts with `http`. If you pass in HTML that happens to have a line beginning with a URL, then `Source#url?` returns true, and IMGKit tries to retrieve content from `http://{HTML CONTENT}`.

For example:

```ruby
html = "

some text with a non-linked URL
http://google.com/

"

IMGKit::Source.new(html).url? # => true
```

This is happening because the regular expression in `Source#url?` is matching each line in the input. To fix this, you could use a regular expression that tests for URLs more comprehensively, or you could change the regular expression from `/^http/` to `/\Ahttp/`. (In other words, change from matching the beginnings of lines to matching the beginning of the entire string.) The latter solution is simpler, but it still will fail if someone happens to have HTML that begins with a URL.

Let me know which solution you prefer, and I can provide a pull request.

Thanks for the library. It's working perfectly for me otherwise.

Chris