Rev 4783: (jam) Fix bug #433779 by sanitizing '\r' in commit messages. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Nov 3 21:31:26 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4783 [merge]
revision-id: pqm at pqm.ubuntu.com-20091103213122-868c6l4jp94gpi8h
parent: pqm at pqm.ubuntu.com-20091103035826-tr4qa6fznzmirgiq
parent: john at arbash-meinel.com-20091103202425-uc4t20tckfla3z7r
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-11-03 21:31:22 +0000
message:
  (jam) Fix bug #433779 by sanitizing '\r' in commit messages.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
=== modified file 'NEWS'
--- a/NEWS	2009-11-03 03:58:26 +0000
+++ b/NEWS	2009-11-03 20:24:25 +0000
@@ -21,6 +21,11 @@
 Bug Fixes
 *********
 
+* Sanitize commit messages that come in from the '-m' flag. We translate
+  '\r\n' => '\n' and a plain '\r' => '\n'. The storage layer doesn't
+  allow those because XML store silently translate it anyway. (The parser
+  auto-translates \r\n => \n in ways that are hard for us to catch.)
+
 Improvements
 ************
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-10-29 21:13:16 +0000
+++ b/bzrlib/builtins.py	2009-11-03 20:24:25 +0000
@@ -3027,6 +3027,9 @@
         def get_message(commit_obj):
             """Callback to get commit message"""
             my_message = message
+            if my_message is not None and '\r' in my_message:
+                my_message = my_message.replace('\r\n', '\n')
+                my_message = my_message.replace('\r', '\n')
             if my_message is None and not file:
                 t = make_commit_message_template_encoded(tree,
                         selected_list, diff=show_diff,

=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py	2009-08-28 05:00:33 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py	2009-11-03 20:24:25 +0000
@@ -170,6 +170,24 @@
         self.assertEqual(err, 'Committing to: %s\n'
                          'Committed revision 2.\n' % expected)
 
+    def test_commit_sanitizes_CR_in_message(self):
+        # See bug #433779, basically Emacs likes to pass '\r\n' style line
+        # endings to 'bzr commit -m ""' which breaks because we don't allow
+        # '\r' in commit messages. (Mostly because of issues where XML style
+        # formats arbitrarily strip it out of the data while parsing.)
+        # To make life easier for users, we just always translate '\r\n' =>
+        # '\n'. And '\r' => '\n'.
+        a_tree = self.make_branch_and_tree('a')
+        self.build_tree(['a/b'])
+        a_tree.add('b')
+        self.run_bzr(['commit',
+                      '-m', 'a string\r\n\r\nwith mixed\r\rendings\n'],
+                     working_dir='a')
+        rev_id = a_tree.branch.last_revision()
+        rev = a_tree.branch.repository.get_revision(rev_id)
+        self.assertEqualDiff('a string\n\nwith mixed\n\nendings\n',
+                             rev.message)
+
     def test_commit_merge_reports_all_modified_files(self):
         # the commit command should show all the files that are shown by
         # bzr diff or bzr status when committing, even when they were not




More information about the bazaar-commits mailing list