Explorar o código

HUE-6115 [core] Fix document paths for names with unicode characters

Jenny Kim %!s(int64=8) %!d(string=hai) anos
pai
achega
979a98d
Modificáronse 2 ficheiros con 19 adicións e 3 borrados
  1. 2 3
      desktop/core/src/desktop/models.py
  2. 17 0
      desktop/core/src/desktop/tests_doc2.py

+ 2 - 3
desktop/core/src/desktop/models.py

@@ -32,7 +32,6 @@ from django.core.urlresolvers import reverse, NoReverseMatch
 from django.db import connection, models, transaction
 from django.db.models import Q
 from django.db.models.query import QuerySet
-from django.template.defaultfilters import urlencode
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
 from settings import HUE_DESKTOP_VERSION
@@ -1074,7 +1073,7 @@ class Document2(models.Model):
 
   @property
   def path(self):
-    quoted_name = urllib.quote(self.name)
+    quoted_name = urllib.quote(self.name.encode('utf-8'))
     if self.parent_directory:
       return '%s/%s' % (self.parent_directory.path, quoted_name)
     else:
@@ -1146,7 +1145,7 @@ class Document2(models.Model):
     return {
       'owner': self.owner.username,
       'name': self.name,
-      'path': urlencode(self.path or '/'),
+      'path': self.path or '/',
       'description': self.description,
       'uuid': self.uuid,
       'id': self.id,

+ 17 - 0
desktop/core/src/desktop/tests_doc2.py

@@ -879,6 +879,23 @@ class TestDocument2Permissions(object):
     assert_true('history.sql' in doc_names)
 
 
+  def test_unicode_name(self):
+    doc = Document2.objects.create(name='My Bundle a voté « non » à l’accord', type='oozie-workflow2', owner=self.user,
+                                   data={}, parent_directory=self.home_dir)
+
+    # Verify that home directory contents return correctly
+    response = self.client.get('/desktop/api2/doc/', {'uuid': self.home_dir.uuid})
+    data = json.loads(response.content)
+    assert_equal(0, data['status'])
+
+    # Verify that the doc's path is escaped
+    response = self.client.get('/desktop/api2/doc/', {'uuid': doc.uuid})
+    data = json.loads(response.content)
+    assert_equal(0, data['status'])
+    path = data['document']['path']
+    assert_equal('/My%20Bundle%20a%20vot%C3%A9%20%C2%AB%20non%20%C2%BB%20%C3%A0%20l%E2%80%99accord', path)
+
+
 class TestDocument2ImportExport(object):
 
   def setUp(self):