benjreinhart commented on a change in pull request #13735: URL: https://github.com/apache/superset/pull/13735#discussion_r602554564
########## 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" Review comment: I updated the implementation to be a bit more clever after some more testing in google sheets and excel. Best I can tell, this gets the job done without being overly intrusive. Some interesting things I found while testing: * Many resources say that a leading space will work the same as a leading single quote, but I found that Google sheets will ignore a leading space and evaluate the command * Google Sheets seems to hide leading single quote while Excel did not * Pandas seems to remove the leading double quotes -- 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]
