wordmove 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,10 +41,19 @@ module Wordmove
41
41
  end
42
42
 
43
43
  def serialized_replace!(source_field, dest_field)
44
- sql_content.gsub!(/s:(?:\d+):(\\*['"])(.*?)\1;/) do |match|
45
- delimiter, string = $1, $2
46
- string.gsub!(/#{Regexp.escape(source_field)}/, dest_field)
47
- %(s:#{string.length}:#{delimiter}#{string}#{delimiter};)
44
+ length_delta = source_field.length - dest_field.length
45
+
46
+ sql_content.gsub!(/s:(\d+):([\\]*['"])(.*?)\2;/) do |match|
47
+ length = $1.to_i
48
+ delimiter = $2
49
+ string = $3
50
+
51
+ string.gsub!(/#{Regexp.escape(source_field)}/) do |match|
52
+ length -= length_delta
53
+ dest_field
54
+ end
55
+
56
+ %(s:#{length}:#{delimiter}#{string}#{delimiter};)
48
57
  end
49
58
  end
50
59
 
@@ -1,3 +1,3 @@
1
1
  module Wordmove
2
- VERSION = "1.0.10"
2
+ VERSION = "1.0.11"
3
3
  end
@@ -109,6 +109,15 @@ describe Wordmove::SqlMover do
109
109
  end
110
110
  end
111
111
 
112
+ context "given strings with escaped content" do
113
+ let(:content) { 's:6:"dump\"\"";' }
114
+
115
+ it "should calculate the correct final length" do
116
+ sql_mover.serialized_replace!('dump', 'sausage')
117
+ sql_mover.sql_content.should == 's:9:"sausage\"\"";'
118
+ end
119
+ end
120
+
112
121
  context "given multiple types of string quoting" do
113
122
  let(:content) { "a:3:{s:20:\\\"http://dump.com/spam\\\";s:6:'foobar';s:22:'http://dump.com/foobar';s:8:'sausages';}" }
114
123
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordmove
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-03 00:00:00.000000000 Z
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colored