<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coffee Powered &#187; usability</title>
	<atom:link href="http://www.coffeepowered.net/tag/usability/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coffeepowered.net</link>
	<description>code and content</description>
	<lastBuildDate>Mon, 09 Jan 2012 18:32:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Quick tip: Strip URLs before parsing!</title>
		<link>http://www.coffeepowered.net/2009/03/28/quick-tip-strip-urls-before-parsing/</link>
		<comments>http://www.coffeepowered.net/2009/03/28/quick-tip-strip-urls-before-parsing/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 08:09:32 +0000</pubDate>
		<dc:creator>Chris Heald</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[uri]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.coffeepowered.net/?p=170</guid>
		<description><![CDATA[Rather than roll my own URL regexes, I prefer to let the existing libraries do the heavy lifting. Ruby has a uri library which is fantastic for parsing (and validating) URLs. For example, something like this might be used in a model validation: I noticed a bit ago that I started getting invalid URL errors [...]]]></description>
			<content:encoded><![CDATA[<p>Rather than roll my own URL regexes, I prefer to let the existing libraries do the heavy lifting. Ruby has a <code>uri</code> library which is fantastic for parsing (and validating) URLs.</p>
<p>For example, something like this might be used in a model validation:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'uri'

def validate_url(url)
	parsed_uri = URI::parse(url)
rescue URI::InvalidURIError
	errors.add :url, &quot;Sorry, that doesn't look like a valid URL&quot;
end
</pre>
<p>I noticed a bit ago that I started getting invalid URL errors where there shouldn&#8217;t be any. After far too long spent in the library&#8217;s code, I realized my error: the URLs were being pasted with a trailing space. Stripping the string before attempting to parse it fixed it right up.</p>
<p>I&#8217;d argue that URI::parse should likely strip any incoming strings, but in the meantime, remember to strip your user input before trying to determine whether it&#8217;s valid or not, or you may end up with frustrated users.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coffeepowered.net/2009/03/28/quick-tip-strip-urls-before-parsing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

