On Mon, Sep 28, 2009 at 1:11 PM, Rob Biedenharn
<Rob / agileconsultingllc.com> wrote:
> On Sep 27, 2009, at 11:48 PM, Hunt Jon wrote:
>
>> Hi - I'm working on the script below, which attempts at getting
>> a user input and validate that the input is formed like a URL.
>> And if the user fails to input, it should ask again.
>>
>> require 'uri'
>> puts "Type a URL"
>> begin
>> =A0url =3D gets.chomp
>> =A0URI.parse(url) # should raise if a variable 'url' is malformed.
>> rescue URI::InvalidURIError
>> =A0puts "That is not a valid URL. Try again."
>> =A0retry
>> end
>>
>> I expect that if I run "URI.parse()" it should raise an error, but
>> it doesn't happen.
>>
>> Can anybody help me on this one?
>>
>> Jon
>
> require 'uri'
> print "Type a URL: "
> begin
> =A0url =3D gets.chomp
> =A0puts "You said: #{url.inspect}"
> =A0uri =3D URI.parse(url) # should raise if a variable 'url' is malformed=
.
> =A0puts uri.inspect
> rescue URI::InvalidURIError
> =A0puts "That is not a valid URL. Try again."
> =A0retry
> end
>
> Try getting a little bit more information out (and post what input you ar=
e
> trying that you expect to be malformed).
>
> Note that some URI's are HTTP and some might be Generic. =A0There are a l=
ot
> more types of URI that just those that start with http://. =A0Have you ev=
er
> seen a jdbc resource string?
>
> -Rob

I expect a user to input a HTTP or HTTPS URL. e.g., http://abcdef.gov
Maybe using URI seems *too* generic after the research as 'uri' means
different protocols, not just http/https.

I'll look into it. Perhaps using Regexp match would be better.

Jon