Эх сурвалжийг харах

[metastore] Do not concatenate spaces in cells result

Romain Rigaux 11 жил өмнө
parent
commit
556d9fdf90

+ 4 - 4
apps/beeswax/src/beeswax/tests.py

@@ -243,7 +243,7 @@ for x in sys.stdin:
   def test_result_escaping(self):
     # Check for XSS and NULL display
     QUERY = """
-      SELECT 'abc', 1.0, 1=1, 1, 1/0, '<a>lala</a>lulu' from test LIMIT 3;
+      SELECT 'abc', 1.0, 1=1, 1, 1/0, '<a>lala</a>lulu', 'some   spaces' from test LIMIT 3;
     """
     response = _make_query(self.client, QUERY, local=False)
     content = json.loads(response.content)
@@ -253,9 +253,9 @@ for x in sys.stdin:
     content = fetch_query_result_data(self.client, response)
 
     assert_equal([
-        [u'abc', 1.0, True, 1, u'NULL', u'&lt;a&gt;lala&lt;/a&gt;lulu'],
-        [u'abc', 1.0, True, 1, u'NULL', u'&lt;a&gt;lala&lt;/a&gt;lulu'],
-        [u'abc', 1.0, True, 1, u'NULL', u'&lt;a&gt;lala&lt;/a&gt;lulu'],
+        [u'abc', 1.0, True, 1, u'NULL', u'&lt;a&gt;lala&lt;/a&gt;lulu', 'some&nbsp;&nbsp;&nbsp;spaces'],
+        [u'abc', 1.0, True, 1, u'NULL', u'&lt;a&gt;lala&lt;/a&gt;lulu', 'some&nbsp;&nbsp;&nbsp;spaces'],
+        [u'abc', 1.0, True, 1, u'NULL', u'&lt;a&gt;lala&lt;/a&gt;lulu', 'some&nbsp;&nbsp;&nbsp;spaces'],
       ], content["results"], content)
 
   def test_query_with_udf(self):

+ 4 - 1
apps/metastore/src/metastore/templates/describe_table.mako

@@ -14,6 +14,8 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 <%!
+from django.utils.html import escape
+
 from desktop.lib.i18n import smart_unicode
 from desktop.views import commonheader, commonfooter
 from django.utils.translation import ugettext as _
@@ -27,6 +29,7 @@ from django.utils.translation import ugettext as _
   else:
     view_or_table_noun = _("Table")
 %>
+
 ${ commonheader(_("%s : %s") % (view_or_table_noun, table.name), app_name, user) | n,unicode }
 ${ components.menubar() }
 
@@ -130,7 +133,7 @@ ${ components.menubar() }
                         % if item is None:
                           NULL
                         % else:
-                          ${ smart_unicode(item, errors='ignore') }
+                          ${ escape(smart_unicode(item, errors='ignore')).replace(' ', '&nbsp;') | n,unicode }
                         % endif
                       </td>
                     % endfor