implement 'should map extra base32 characters to filenames'
authorLunar <lunar@anargeek.net>
Mon, 2 Aug 2010 10:55:43 +0000 (12:55 +0200)
committerLunar <lunar@anargeek.net>
Mon, 2 Aug 2010 10:55:43 +0000 (12:55 +0200)
coquelicot.rb
test_coquelicot.rb

index 37dfab2..ee9dd6f 100644 (file)
@@ -288,6 +288,14 @@ end
 def gen_random_pass
   gen_random_base32(options.random_pass_length)
 end
+def remap_base32_extra_characters(str)
+  map = {}
+  FILENAME_CHARS.each { |c| map[c] = c; map[c.upcase] = c }
+  map.merge!({ '1' => 'l', '0' => 'o' })
+  result = ''
+  str.each_char { |c| result << map[c] }
+  result
+end
 
 def password_match?(password)
   return TRUE if settings.upload_password.nil?
@@ -364,10 +372,13 @@ def send_stored_file(link, pass)
 end
 
 get '/:link-:pass' do |link, pass|
+  link = remap_base32_extra_characters(link)
+  pass = remap_base32_extra_characters(pass)
   not_found unless send_stored_file(link, pass)
 end
 
 get '/:link' do |link|
+  link = remap_base32_extra_characters(link)
   not_found unless depot.file_exists? link
   @link = link
   haml :enter_file_key
index bf77c44..ce9bc71 100644 (file)
@@ -197,5 +197,20 @@ describe 'Coquelicot' do
     end
   end
 
-  it "should map extra base32 characters to filenames"
+  it "should map extra base32 characters to filenames" do
+    post '/upload', 'file' => Rack::Test::UploadedFile.new(__FILE__, 'text/x-script.ruby'),
+                    'expire' => 60,  # 1 hour
+                    'upload_password' => UPLOAD_PASSWORD
+    last_response.redirect?.should be_true
+    follow_redirect!
+    last_response.should be_ok
+    doc = Hpricot(last_response.body)
+    url = (doc/'a').collect { |a| a.attributes['href'] }.
+      select { |h| h.start_with? "http://#{last_request.host}/" }[0]
+    splitted = url.split('/')
+    name = splitted[-1].upcase.gsub(/O/, '0').gsub(/L/, '1')
+    get "#{splitted[0..-2].join '/'}/#{name}"
+    last_response.should be_ok
+    last_response['Content-Type'].should eql('text/x-script.ruby')
+  end
 end