robdiciuccio commented on a change in pull request #13735:
URL: https://github.com/apache/superset/pull/13735#discussion_r600079540
##########
File path: superset/charts/api.py
##########
@@ -484,12 +484,7 @@ def get_data_response(
if result_format == ChartDataResultFormat.CSV:
# return the first result
data = result["queries"][0]["data"]
- return CsvResponse(
- data,
- status=200,
- headers=generate_download_headers("csv"),
- mimetype="application/csv",
Review comment:
Do we need to override the default `text/csv` mimetype? The new default
seems to be the correct value.
##########
File path: superset/views/base.py
##########
@@ -479,6 +479,7 @@ class CsvResponse(Response): # pylint:
disable=too-many-ancestors
"""
charset = conf["CSV_EXPORT"].get("encoding", "utf-8")
+ default_mimetype = "text/csv"
Review comment:
👍
##########
File path: tests/utils/csv_tests.py
##########
@@ -0,0 +1,60 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=no-self-use
+import io
+
+import pandas as pd
+import pytest
+
+from superset.utils import csv
+
+
+def test_escape_value():
+ result = csv.escape_value("value")
+ assert result == "value"
+
+ result = csv.escape_value("-10")
+ assert result == "-10"
+
+ result = csv.escape_value("@value")
+ assert result == "'@value"
+
+ result = csv.escape_value("+value")
+ assert result == "'+value"
+
+ result = csv.escape_value("-value")
+ assert result == "'-value"
+
+ result = csv.escape_value("=value")
+ assert result == "'=value"
+
+ result = csv.escape_value("|value")
+ assert result == "'\|value"
+
+ result = csv.escape_value("%value")
+ assert result == "'%value"
+
+ result = csv.escape_value("=cmd|' /C calc'!A0")
+ assert result == "'=cmd\|' /C calc'!A0"
+
+
+def test_df_to_escaped_csv():
+ csv_str = "col_a,=col_b\n-10,=cmd|' /C calc'!A0\na,=b"
Review comment:
Can we add another row to assert that both the column headers and the
data are escaped?
##########
File path: superset/views/core.py
##########
@@ -437,10 +437,7 @@ def generate_json(
) -> FlaskResponse:
if response_type == utils.ChartDataResultFormat.CSV:
return CsvResponse(
- viz_obj.get_csv(),
- status=200,
- headers=generate_download_headers("csv"),
- mimetype="application/csv",
+ viz_obj.get_csv(), headers=generate_download_headers("csv")
Review comment:
Do we still need `status` here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]