<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>.gitignore</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -11,6 +11,9 @@ class Admin::FlowMetersController &lt; ApplicationController
   rescue ActiveRecord::RecordInvalid =&gt; e
     flash[:error] = &quot;#{e.message}&quot;
     redirect_to admin_flow_meters_url
+  rescue FlowMeter::DataMismatch =&gt; e
+    flash[:error] = &quot;#{e.message}&quot;
+    redirect_to admin_flow_meters_url
   end
   
   def destroy</diff>
      <filename>app/controllers/admin/flow_meters_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,9 @@
 class FlowMeter &lt; ActiveRecord::Base
+  class DataMismatch &lt; StandardError; end
+  
   before_save :set_default_status
+  after_validation :clean_catch_url
+  after_validation :clean_redirect_url
   
   validates_presence_of :catch_url, :on =&gt; :create, :message =&gt; &quot;can't be blank&quot;
   validates_presence_of :redirect_url, :on =&gt; :create, :message =&gt; &quot;can't be blank&quot;
@@ -7,11 +11,22 @@ class FlowMeter &lt; ActiveRecord::Base
   validates_uniqueness_of :catch_url
     
   validate :catch_url_not_restricted
-    
-  protected
+  validate :redirect_url_not_restricted
   
-  def set_default_status
-    self.status = '307' if self.status.blank?
+  def display_url(att)
+    self[att] == '/' ? cleaned_up_url(att) : &quot;/#{cleaned_up_url(att)}&quot;
+  end
+  
+  [:catch_url, :redirect_url].each do |att|
+    define_method &quot;#{att.to_s}_for_display&quot; do
+      display_url(att)
+    end
+  end
+  
+  def cleaned_up_url(att)
+    new_att = self[att].gsub(%r{//+},'/').gsub(%r{\s+},'')
+    new_att.gsub!(%r{^/},'') unless new_att == '/'
+    new_att
   end
   
   def catch_url_not_restricted
@@ -19,4 +34,30 @@ class FlowMeter &lt; ActiveRecord::Base
       errors.add(:catch_url, 'cannot catch the admin url')
     end
   end
+  
+  def redirect_url_not_restricted
+    if catch_url == redirect_url
+      raise DataMismatch, &quot;Catch URL and Redirect URL may not be the same.&quot;
+    end
+  end
+  
+  protected
+  
+  def set_default_status
+    self.status = '307' if self.status.blank?
+  end
+  
+  def clean_catch_url
+    clean_url(:catch_url) unless catch_url.blank?
+  end
+  
+  def clean_redirect_url
+    clean_url(:redirect_url) unless redirect_url.blank?
+  end
+  
+  def clean_url(att)
+    if !self[att].blank? and !self[att].nil?
+      self.update_attribute(att, cleaned_up_url(att))
+    end
+  end
 end</diff>
      <filename>app/models/flow_meter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,8 +11,8 @@
     %tbody
     - @flow_meters.each do |flow_meter|
       %tr
-        %td= flow_meter.catch_url
-        %td= flow_meter.redirect_url
+        %td= flow_meter.catch_url_for_display
+        %td= flow_meter.redirect_url_for_display
         %td= flow_meter.status
         %td= link_to &quot;Delete&quot;, admin_flow_meter_path(flow_meter), :method =&gt; :delete
     %tr</diff>
      <filename>app/views/admin/flow_meters/index.html.haml</filename>
    </modified>
    <modified>
      <diff>@@ -40,4 +40,57 @@ describe FlowMeter do
     @flow_meter2.valid?
     @flow_meter2.errors.on(:catch_url).should match(/has already been taken/)
   end
-end
+  
+  it &quot;should remove the first character from catch_url beginning with a slash&quot; do
+    @flow_meter.save
+    @flow_meter.catch_url.should == 'stuff'
+  end
+  
+  it &quot;should remove the first character from redirect_url beginning with a slash&quot; do
+    @flow_meter.save
+    @flow_meter.redirect_url.should == 'things'
+  end
+  
+  it &quot;should remove consecutive slashes from the catch_url before saving&quot; do
+    @flow_meter.catch_url = &quot;///slasher&quot;
+    @flow_meter.save
+    @flow_meter.catch_url.should == 'slasher'
+  end
+  
+  it &quot;should remove consecutive slashes from the redirect_url before saving&quot; do
+    @flow_meter.redirect_url = &quot;///chop&quot;
+    @flow_meter.save
+    @flow_meter.redirect_url.should == 'chop'
+  end
+  
+  it &quot;should remove all whitespace from catch_url before saving&quot; do
+    @flow_meter.catch_url = &quot;hello there&quot;
+    @flow_meter.save
+    @flow_meter.catch_url.should == 'hellothere'
+  end
+  
+  it &quot;should remove all whitespace from redirect_url before saving&quot; do
+    @flow_meter.redirect_url = &quot;how are you&quot;
+    @flow_meter.save
+    @flow_meter.redirect_url.should == 'howareyou'
+  end
+  
+  it &quot;should allow '/' as the redirect_url&quot; do
+    @flow_meter.redirect_url = &quot;/&quot;
+    @flow_meter.save
+    @flow_meter.redirect_url.should == '/'
+  end
+
+  it &quot;should provide a catch_url_for_display which includes a leading slash&quot; do
+    @flow_meter.catch_url_for_display.should == '/stuff'
+  end
+  
+  it &quot;should provide a redirect_url_for_display which includes a leading slash&quot; do
+    @flow_meter.redirect_url_for_display.should == '/things'
+  end
+
+  it &quot;should err with 'Catch URL and Redirect URL may not be the same.' when given a catch_url that matches the redirect_url&quot; do
+    @flow_meter.redirect_url = &quot;/stuff&quot;
+    lambda {@flow_meter.save!}.should raise_error(FlowMeter::DataMismatch, &quot;Catch URL and Redirect URL may not be the same.&quot;)
+  end
+end
\ No newline at end of file</diff>
      <filename>spec/models/flow_meter_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>3ea0bfbabe4d639acda267aa92ceb73f79b40450</id>
    </parent>
  </parents>
  <author>
    <name>Jim Gay</name>
    <email>jim@saturnflyer.com</email>
  </author>
  <url>http://github.com/jomz/radiant-vapor-extension/commit/77a8879b11e9821ee840381d7bb7d6a88441725f</url>
  <id>77a8879b11e9821ee840381d7bb7d6a88441725f</id>
  <committed-date>2008-08-04T11:39:09-07:00</committed-date>
  <authored-date>2008-08-04T11:39:09-07:00</authored-date>
  <message>better restrictions on URLs</message>
  <tree>a92df5ba1df06577bd0c7d7159b622e931213d8f</tree>
  <committer>
    <name>Jim Gay</name>
    <email>jim@saturnflyer.com</email>
  </committer>
</commit>
