]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/parser.py
Decode patch from UTF-8 while parsing from stdin
[patchwork] / apps / patchwork / parser.py
index abec782f4f7c75cf74d7a83ef73b07f680addbdd..24631b739822fde096f3f748343410be8ec2be3d 100644 (file)
@@ -63,8 +63,7 @@ def parse_patch(text):
     lc = (0, 0)
     hunk = 0
 
-
-    for line in text.split('\n'):
+    for line in text.decode('utf-8').split('\n'):
         line += '\n'
 
         if state == 0:
@@ -133,6 +132,9 @@ def parse_patch(text):
                 lc[0] -= 1
             elif line.startswith('+'):
                 lc[1] -= 1
+            elif line.startswith('\ No newline at end of file'):
+                # Special case: Not included as part of the hunk's line count
+                pass
             else:
                 lc[0] -= 1
                 lc[1] -= 1
@@ -219,7 +221,10 @@ def main(args):
 
     (options, args) = parser.parse_args()
 
-    (patch, comment) = parse_patch(sys.stdin.read())
+    # decode from (assumed) UTF-8
+    content = sys.stdin.read().decode('utf-8')
+
+    (patch, comment) = parse_patch(content)
 
     if options.print_hash and patch:
         print hash_patch(patch).hexdigest()