Fix crash in tidytool.py when processing non-ASCII Robot file 03/35403/4
authorJozef Behran <jbehran@cisco.com>
Thu, 25 Feb 2016 13:55:56 +0000 (14:55 +0100)
committerJozef Behran <jbehran@cisco.com>
Thu, 25 Feb 2016 16:20:52 +0000 (17:20 +0100)
Change-Id: Ie28116c94db9a03129aca7ac4c0416719847743f
Signed-off-by: Jozef Behran <jbehran@cisco.com>
tools/robot_check/tidytool.py

index 1f69ca293aceea89149a34ace5d026835d4e95d3..d20abd9b1d175357daa56e2197c282b1d294ed40 100644 (file)
@@ -39,6 +39,11 @@ def check_quietly(FileSpec):
     except (IOError, OSError), e:
         Error(FileSpec, "Not accessible: " + str(e))
         return
+    try:
+        Data = Data.decode("utf8")
+    except:
+        Error(FileSpec, "Has invalid UTF8 data")
+        return
     TidyTool = robot.tidy.Tidy()
     CleanedData = TidyTool.file(FileSpec)
     if Data != CleanedData:
@@ -61,6 +66,7 @@ def tidy(FileSpec):
     TidyTool = robot.tidy.Tidy()
     try:
         CleanedData = TidyTool.file(FileSpec)
+        CleanedData = CleanedData.encode("utf8")
         open(FileSpec, "w").write(CleanedData)
     except (IOError, OSError), e:
         Error(FileSpec, "Not accessible: " + str(e))