2007-11-28     Andrew Ruthven
        Be more wary about processing what the backend has sent us.
+               This includes cleaning up some invalid UTF-8 characters.
        Add support for reading XML from a file.
        Be a bit more forgiving on the XML we're receiving.
        Show how much disk space is used - currently only total.
 
   $parser->recover_silently(1)
     unless $verbose;
 
+  clean_xml(\$status);
+
   my $xml = eval { $parser->parse_string( $status ) };
 
   if ($@) {
   return $myth;
 }
 
+# We are sometimes passed dodgy XML from MythTV, make some attempts to clean
+# it.
+sub clean_xml {
+  my ($xml) = shift;
+
+  # Deal to invalid Unicode.
+  for my $bad ("�", "�") {
+    if ($$xml =~ s/$bad/?/g) {
+      warn "Found and replaced: $bad\n"
+        if $verbose;
+    }
+  }
+}
+
 sub process_xml {
   my ($block, $xml) = @_;