Bug 1061684 - Normalize path separators in JAR paths. r=mshal, a=lmandel
authorGregory Szorc <gps@mozilla.com>
Wed, 03 Sep 2014 10:42:34 -0700
changeset 224900 4c1c54b7671eaa6f135f4d35c0566540c129dc46
parent 224899 80e3a7e6be3584e0975863677e080c4ca4094123
child 224901 75e38ef65862bd371f3c607b4a1b94a1edfaad11
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmshal, lmandel
Bug 1061684 - Normalize path separators in JAR paths. r=mshal, a=lmandel The forward slash appears to be the standard path separator in zip/JAR files. Accept back slashes when adding paths to a JAR.
--- a/python/mozbuild/mozpack/mozjar.py
+++ b/python/mozbuild/mozpack/mozjar.py
@@ -575,16 +575,18 @@ class JarWriter(object):
         True), it is only really compressed if the compressed size is smaller
         than the uncompressed size.
         The mode option gives the unix permissions that should be stored
         for the jar entry.
         The given data may be a buffer, a file-like instance, a Deflater or a
         JarFileReader instance. The latter two allow to avoid uncompressing
         data to recompress it.
+        name = mozpack.path.normsep(name)
         if name in self._contents:
             raise JarWriterError("File %s already in JarWriter" % name)
         if compress is None:
             compress = self._compress
         if (isinstance(data, JarFileReader) and data.compressed == compress) \
                 or (isinstance(data, Deflater) and data.compress == compress):
             deflater = data
--- a/python/mozbuild/mozpack/test/test_mozjar.py
+++ b/python/mozbuild/mozpack/test/test_mozjar.py
@@ -130,31 +130,39 @@ class TestJar(unittest.TestCase):
     def test_jar(self):
         s = MockDest()
         with JarWriter(fileobj=s, optimize=self.optimize) as jar:
             jar.add('foo', 'foo')
             self.assertRaises(JarWriterError, jar.add, 'foo', 'bar')
             jar.add('bar', 'aaaaaaaaaaaaanopqrstuvwxyz')
             jar.add('baz/qux', 'aaaaaaaaaaaaanopqrstuvwxyz', False)
+            jar.add('baz\\backslash', 'aaaaaaaaaaaaaaa')
         files = [j for j in JarReader(fileobj=s)]
         self.assertEqual(files[0].filename, 'foo')
         self.assertEqual(files[0].read(), 'foo')
         self.assertEqual(files[1].filename, 'bar')
         self.assertEqual(files[1].read(), 'aaaaaaaaaaaaanopqrstuvwxyz')
         self.assertEqual(files[2].filename, 'baz/qux')
         self.assertEqual(files[2].read(), 'aaaaaaaaaaaaanopqrstuvwxyz')
+        if os.sep == '\\':
+            self.assertEqual(files[3].filename, 'baz/backslash',
+                'backslashes in filenames on Windows should get normalized')
+        else:
+            self.assertEqual(files[3].filename, 'baz\\backslash',
+                'backslashes in filenames on POSIX platform are untouched')
         s = MockDest()
         with JarWriter(fileobj=s, compress=False,
                        optimize=self.optimize) as jar:
             jar.add('bar', 'aaaaaaaaaaaaanopqrstuvwxyz')
             jar.add('foo', 'foo')
             jar.add('baz/qux', 'aaaaaaaaaaaaanopqrstuvwxyz', True)
         jar = JarReader(fileobj=s)