Rev 4670: Do not add files whose name contains new lines or carriage returns in http://bazaar.launchpad.net/~lifeless/bzr/bug-3918

Robert Collins robertc at robertcollins.net
Mon Sep 28 03:02:42 BST 2009


At http://bazaar.launchpad.net/~lifeless/bzr/bug-3918

------------------------------------------------------------
revno: 4670
revision-id: robertc at robertcollins.net-20090928020230-tmaohfuek0nf2kbm
parent: pqm at pqm.ubuntu.com-20090925210528-kxssbjs9to8ob22a
committer: Robert Collins <robertc at robertcollins.net>
branch nick: bug-3918
timestamp: Mon 2009-09-28 12:02:30 +1000
message:
  Do not add files whose name contains new lines or carriage returns
=== modified file 'NEWS'
--- a/NEWS	2009-09-25 21:05:28 +0000
+++ b/NEWS	2009-09-28 02:02:30 +0000
@@ -2,6 +2,37 @@
 Bazaar Release Notes
 ####################
 
+2.0 series (not released)
+#########################
+
+Compatibility Breaks
+********************
+
+New Features
+************
+
+Bug Fixes
+*********
+
+* ``bzr add`` in a tree that has files with ``\r`` or ``\n`` in the
+  filename will issue a warning and skip over those files.
+  (Robert Collins, #3918)
+
+Improvements
+************
+
+Documentation
+*************
+
+API Changes
+***********
+
+Internals
+*********
+
+Testing
+*******
+
 bzr 2.0.1
 ##########
 

=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py	2009-09-07 23:14:05 +0000
+++ b/bzrlib/mutabletree.py	2009-09-28 02:02:30 +0000
@@ -23,6 +23,7 @@
 from bzrlib.lazy_import import lazy_import
 lazy_import(globals(), """
 import os
+import re
 
 from bzrlib import (
     add,
@@ -427,6 +428,7 @@
                 dirs_to_add.append((path, None))
             prev_dir = path.raw_path
 
+        illegalpath_re = re.compile(r'[\r\n]')
         # dirs_to_add is initialised to a list of directories, but as we scan
         # directories we append files to it.
         # XXX: We should determine kind of files when we scan them rather than
@@ -443,6 +445,9 @@
             if not InventoryEntry.versionable_kind(kind):
                 warning("skipping %s (can't add file of kind '%s')", abspath, kind)
                 continue
+            if illegalpath_re.search(directory.raw_path):
+                warning("skipping %r (contains \\n or \\r)" % abspath)
+                continue
 
             if parent_ie is not None:
                 versioned = directory.base_path in parent_ie.children

=== modified file 'bzrlib/tests/per_workingtree/test_smart_add.py'
--- a/bzrlib/tests/per_workingtree/test_smart_add.py	2009-07-10 07:14:02 +0000
+++ b/bzrlib/tests/per_workingtree/test_smart_add.py	2009-09-28 02:02:30 +0000
@@ -51,6 +51,18 @@
         self.assertEqual([('', 'V', 'directory'), ('a', 'V', 'file')],
                          files)
 
+    def assertFilenameSkipped(self, filename):
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/'+filename])
+        tree.smart_add(['tree'])
+        self.assertEqual(None, tree.path2id(filename))
+
+    def test_path_containing_newline_skips(self):
+        self.assertFilenameSkipped('a\nb')
+
+    def test_path_containing_carriagereturn_skips(self):
+        self.assertFilenameSkipped('a\rb')
+
     def test_save_false(self):
         """Dry-run add doesn't permanently affect the tree."""
         wt = self.make_branch_and_tree('.')




More information about the bazaar-commits mailing list