lib/pliny/log.rb in pliny-0.29.0 vs lib/pliny/log.rb in pliny-0.30.0
- old
+ new
@@ -121,17 +121,21 @@
raise $!
end
end
end
- def quote_string(k, v)
+ def replace_newlines(v)
+ v.gsub("\n", "\\n")
+ end
+
+ def quote_string(v)
if !v.include?('"')
- %{#{k}="#{v}"}
+ %{"#{v}"}
elsif !v.include?("'")
- %{#{k}='#{v}'}
+ %{'#{v}'}
else
- %{#{k}="#{v.gsub(/"/, '\\"')}"}
+ %{"#{v.gsub(/"/, '\\"')}"}
end
end
def unparse(attrs)
attrs.map { |k, v| unparse_pair(k, v) }.compact.join(" ")
@@ -148,14 +152,13 @@
"#{k}=#{format("%.3f", v)}"
elsif v.is_a?(Time)
"#{k}=#{v.iso8601}"
else
v = "#{v}"
- if v =~ /\s/
- quote_string(k, v)
- else
- "#{k}=#{v}"
- end
+ v = replace_newlines(v)
+ v = quote_string(v) if v =~ /\s/
+
+ "#{k}=#{v}"
end
end
end
end