Patchwork D5818: patch: properly escape \ in string literals

login
register
mail settings
Submitter phabricator
Date Feb. 4, 2019, 11:36 p.m.
Message ID <136a3f9b74425642102f6e061895d7f1@localhost.localdomain>
Download mbox | patch
Permalink /patch/38400/
State Not Applicable
Headers show

Comments

phabricator - Feb. 4, 2019, 11:36 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG47c92f8ed128: patch: properly escape \ in string literals (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5818?vs=13745&id=13778

REVISION DETAIL
  https://phab.mercurial-scm.org/D5818

AFFECTED FILES
  mercurial/patch.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -753,7 +753,7 @@ 
             for l in x.hunk:
                 lines.append(l)
                 if l[-1:] != '\n':
-                    lines.append("\n\ No newline at end of file\n")
+                    lines.append("\n\\ No newline at end of file\n")
         self.backend.writerej(self.fname, len(self.rej), self.hunks, lines)
 
     def apply(self, h):
@@ -1305,7 +1305,7 @@ 
             self.hunk.append(u)
 
         l = lr.readline()
-        if l.startswith('\ '):
+        if l.startswith(br'\ '):
             s = self.a[-1][:-1]
             self.a[-1] = s
             self.hunk[-1] = s
@@ -1323,7 +1323,7 @@ 
         hunki = 1
         for x in pycompat.xrange(self.lenb):
             l = lr.readline()
-            if l.startswith('\ '):
+            if l.startswith(br'\ '):
                 # XXX: the only way to hit this is with an invalid line range.
                 # The no-eol marker is not counted in the line range, but I
                 # guess there are diff(1) out there which behave differently.
@@ -1380,7 +1380,7 @@ 
 
     def _fixnewline(self, lr):
         l = lr.readline()
-        if l.startswith('\ '):
+        if l.startswith(br'\ '):
             diffhelper.fixnewline(self.hunk, self.a, self.b)
         else:
             lr.push(l)