lib/wordmove/sql_mover.rb in wordmove-1.0.4 vs lib/wordmove/sql_mover.rb in wordmove-1.0.6
- old
+ new
@@ -41,13 +41,20 @@
end
def serialized_replace!(source_field, dest_field)
length_delta = source_field.length - dest_field.length
- sql_content.gsub!(/s:(\d+):([\\'"]+)#{Regexp.escape(source_field)}/) do |match|
- source_length = $1.to_i
- dest_length = source_length - length_delta
- "s:#{dest_length}:#{$2}#{dest_field}"
+ sql_content.gsub!(/s:(\d+):([\\'"]+)(.*?)\2;/) do |match|
+ length = $1.to_i
+ delimiter = $2
+ string = $3
+
+ string.gsub!(/#{Regexp.escape(source_field)}/) do |match|
+ length -= length_delta
+ dest_field
+ end
+
+ %(s:#{length}:#{delimiter}#{string}#{delimiter};)
end
end
def simple_replace!(source_field, dest_field)
sql_content.gsub!(source_field, dest_field)