Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use slice() instead of regexp captures (Fixes #302)

  • Loading branch information...
commit 7667ff9b63281faea7c1a8ab8a0a02419d7fe380 1 parent 4ff1a01
Brian D. Burns authored Brian D. Burns committed
Showing with 21 additions and 13 deletions.
  1. +3 −2 lib/backup/syncer/cloud/base.rb
  2. +18 −11 spec/syncer/cloud/base_spec.rb
View
5 lib/backup/syncer/cloud/base.rb
@@ -214,8 +214,9 @@ def self.new(*args)
def initialize(directory, line)
@invalid = false
@directory = sanitize(directory)
- @path, @md5 = sanitize(line).chomp.
- match(/^MD5\(([^\)]+)\)= (\w+)$/).captures
+ line = sanitize(line).chomp
+ @path = line.slice(4..-36)
+ @md5 = line.slice(-32..-1)
@relative_path = @path.sub(@directory + '/', '')
end
View
29 spec/syncer/cloud/base_spec.rb
@@ -255,9 +255,10 @@
)
sync_context.expects(:`).with(
"find /dir/to/sync -print0 | xargs -0 openssl md5 2> /dev/null"
- ).returns('MD5(tmp/foo)= 123abcdef')
+ ).returns('MD5(tmp/foo)= 0123456789abcdefghijklmnopqrstuv')
- sync_context.send(:local_hashes).should == 'MD5(tmp/foo)= 123abcdef'
+ sync_context.send(:local_hashes).should ==
+ 'MD5(tmp/foo)= 0123456789abcdefghijklmnopqrstuv'
end
end
@@ -305,7 +306,9 @@
describe '#sync_file' do
let(:local_file) do
- stub(:path => '/dir/to/sync/sync.file', :md5 => 'abc123')
+ stub(
+ :path => '/dir/to/sync/sync.file',
+ :md5 => '0123456789abcdefghijklmnopqrstuv')
end
let(:remote_file) do
stub(:path => 'backups/sync/sync.file')
@@ -329,7 +332,7 @@
context 'when the MD5 checksum matches the remote file' do
before do
- remote_file.stubs(:etag).returns('abc123')
+ remote_file.stubs(:etag).returns('0123456789abcdefghijklmnopqrstuv')
sync_context.stubs(:remote_files).returns(
{ 'sync.file' => remote_file }
)
@@ -348,7 +351,7 @@
context 'when the MD5 checksum does not match the remote file' do
before do
- remote_file.stubs(:etag).returns('dfg456')
+ remote_file.stubs(:etag).returns('vutsrqponmlkjihgfedcba9876543210')
sync_context.stubs(:remote_files).returns(
{ 'sync.file' => remote_file }
)
@@ -436,7 +439,10 @@
describe 'wrapping #initialize and using #sanitize to validate objects' do
context 'when the path is valid UTF-8' do
let(:local_file) do
- local_file_class.new('foo', 'MD5(foo)= foo')
+ local_file_class.new(
+ 'foo',
+ 'MD5(foo)= 0123456789abcdefghijklmnopqrstuv'
+ )
end
it 'should return the new object' do
@@ -450,7 +456,8 @@
context 'when the path contains invalid UTF-8' do
let(:local_file) do
local_file_class.new(
- "/bad/pa\xFFth", "MD5(/bad/pa\xFFth/to/file)= foo"
+ "/bad/pa\xFFth",
+ "MD5(/bad/pa\xFFth/to/file)= 0123456789abcdefghijklmnopqrstuv"
)
end
it 'should return nil and log a warning' do
@@ -473,15 +480,15 @@
before do
local_file_class.any_instance.expects(:sanitize).with(:directory).
- returns('/dir/to/sync')
+ returns('/dir/to/sync')
local_file_class.any_instance.expects(:sanitize).with(:line).
- returns("MD5(/dir/to/sync/subdir/sync.file)= 123abcdef\n")
+ returns("MD5(/dir/to/sync/subdir/sync.file)= 0123456789abcdefghijklmnopqrstuv\n")
end
it 'should determine @path, @relative_path and @md5' do
local_file.path.should == '/dir/to/sync/subdir/sync.file'
local_file.relative_path.should == 'subdir/sync.file'
- local_file.md5.should == '123abcdef'
+ local_file.md5.should == '0123456789abcdefghijklmnopqrstuv'
end
it 'should return nil if the object is invalid' do
@@ -494,7 +501,7 @@
describe '#sanitize' do
let(:local_file) do
- local_file_class.new('foo', 'MD5(foo)= foo')
+ local_file_class.new('foo', 'MD5(foo)= 0123456789abcdefghijklmnopqrstuv')
end
it 'should replace any invalid UTF-8 characters' do
Please sign in to comment.
Something went wrong with that request. Please try again.