Project

General

Profile

Actions

Bug #6520

closed

Invalid url is identified as valid

Added by zheka (Eugene Mirkin) almost 12 years ago. Updated almost 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
1.9.3p125
Backport:
[ruby-core:45344]

Description

(({
1.9.3p125 :006 > require 'uri'
=> true
1.9.3p125 :007 > URI.parse invalid_url
URI::InvalidURIError: bad URI(is not URI?): http://abc</option%3E
1.9.3p125 :009 > invalid_url =~ URI::regexp
=> 0
}))

As you can see, 'parse' behaves correctly (ie raises an exception), while the 'regexp' does not catch the error

Updated by mame (Yusuke Endoh) almost 12 years ago

  • Status changed from Open to Rejected

The following will tell you what is happening.

1.9.3p125 :010 > s[URI.regexp]
=> "http://abc"

URI.regexp is supposed to be used to extract urls from text.

str.scan(URI.regexp) { p $& }

I don't think it is a good idea to use this feature to validate a uri string.

--
Yusuke Endoh

Actions

Also available in: Atom PDF

Like0
Like0