Rev 4782: Fix bug #433779, sanitize '\r' characters in commit. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b3-433779-sanitize-commit-m

John Arbash Meinel john at arbash-meinel.com
Tue Nov 3 18:10:01 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b3-433779-sanitize-commit-m

------------------------------------------------------------
revno: 4782
revision-id: john at arbash-meinel.com-20091103180948-kz82sivw14wscmok
parent: pqm at pqm.ubuntu.com-20091102110512-yw3aimu88nbmvoo9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b3-433779-sanitize-commit-m
timestamp: Tue 2009-11-03 12:09:48 -0600
message:
  Fix bug #433779, sanitize '\r' characters in commit.
  
  This only applies to messages given via '-m'. We already had code that
  read -F in 'text' mode. And if someone is directly using 'tree.commit()'
  we would like them to do the sanitizing.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2009-11-01 05:41:57 +0000
+++ b/NEWS	2009-11-03 18:09:48 +0000
@@ -21,6 +21,12 @@
 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.)
+  (John Arbash Meinel, #433779)
+
 Improvements
 ************
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-10-29 21:13:16 +0000
+++ b/bzrlib/builtins.py	2009-11-03 18:09:48 +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 18:09:48 +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