diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -229,7 +229,7 @@ def unidiff(a, ad, b, bd, fn1, fn2, opts
 
     def checknonewline(lines):
         for text in lines:
-            if text[-1] != '\n':
+            if text[-1:] != '\n':
                 text += "\n\ No newline at end of file\n"
             yield text
 
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -737,7 +737,7 @@ class patchfile(object):
         for x in self.rej:
             for l in x.hunk:
                 lines.append(l)
-                if l[-1] != '\n':
+                if l[-1:] != '\n':
                     lines.append("\n\ No newline at end of file\n")
         self.backend.writerej(self.fname, len(self.rej), self.hunks, lines)