Rev 4701: 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:13:32 GMT 2009


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

------------------------------------------------------------
revno: 4701
revision-id: john at arbash-meinel.com-20091103181319-9rhyiys2wef0k41w
parent: pqm at pqm.ubuntu.com-20091102233914-2rr7qeatw9myuqgt
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b3-433779-sanitize-commit-m
timestamp: Tue 2009-11-03 12:13:19 -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-10-30 15:58:10 +0000
+++ b/NEWS	2009-11-03 18:13:19 +0000
@@ -19,6 +19,10 @@
 
 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 05:49:32 +0000
+++ b/bzrlib/builtins.py	2009-11-03 18:13:19 +0000
@@ -3025,6 +3025,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-26 03:20:32 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py	2009-11-03 18:13:19 +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