Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Strip invalid byte sequences from input

darcs changes --xml might contain invalid UTF-8 byte sequences,
which breaks XML parsing [http://bugs.darcs.net/issue64].
  • Loading branch information...
commit e6ddd9e18719dc398a46e442e5f6d031788292f7 1 parent a19b75d
@kerneis kerneis authored committed
Showing with 7 additions and 1 deletion.
  1. +7 −1 darcs-to-git
View
8 darcs-to-git
@@ -14,6 +14,7 @@ require 'rexml/document'
require 'optparse'
require 'yaml'
require 'pathname'
+require 'iconv'
# Explicitly setting a time zone would cause darcs to only output in
# that timezone hence we couldn't get the actual patch TZ
@@ -112,11 +113,16 @@ def run(*args)
system(*args) || raise("Failed to run: #{args.inspect}")
end
+# cf. Paul Battley, http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/
+def validate_utf8(s)
+ return Iconv.iconv('UTF-8//IGNORE', 'UTF-8', (s + ' ') ).first[0..-2]
+end
+
def output_of(*args)
puts "Running: #{args.inspect}"
output = IO.popen(args.map {|a| "'#{a}'"}.join(' '), 'r') { |p| p.read }
if $?.exitstatus == 0
- return output
+ return validate_utf8(output)
else
raise "Failed to run: #{args.inspect}"
end
Please sign in to comment.
Something went wrong with that request. Please try again.