SameerMesiah97 commented on code in PR #72166:
URL: https://github.com/apache/airflow/pull/72166#discussion_r3874862624
##########
providers/google/src/airflow/providers/google/suite/hooks/drive.py:
##########
@@ -29,6 +29,19 @@
from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
+def _escape_drive_query_value(value: str) -> str:
+ r"""
+ Escape a value for interpolation into a Drive ``q=`` string literal.
+
+ The Drive query language delimits string literals with single quotes and
escapes
+ ``'`` and ``\\`` with a backslash. Values reaching these queries are
frequently
+ object names taken from a source bucket listing rather than written by
hand, so a
+ quote in the value is ordinary input; left unescaped it ends the literal
early and
+ the expression no longer means what the caller intended.
+ """
Review Comment:
I think this would be better:
```
r"""Escape a value for interpolation into a Drive ``q=`` string literal."""
# Drive string literals use single quotes and escape both quotes and
backslashes
# with a backslash. Object names may contain either character, so leaving
them
# unescaped could terminate the literal early and change the query
expression.
```
##########
providers/google/tests/unit/google/suite/hooks/test_drive.py:
##########
@@ -449,3 +449,59 @@ def test_create_file(self, mock_get_conn):
)
mock_execute.assert_called_once()
assert result == {"id": "NEW_FILE_ID", "webViewLink":
"https://example.com/view"}
+
+
[email protected](
+ ("raw", "expected"),
+ [
+ ("plain.csv", "plain.csv"),
+ ("o'brien.csv", "o\\'brien.csv"),
+ ("back\\slash", "back\\\\slash"),
+ ("x' or name!='", "x\\' or name!=\\'"),
Review Comment:
Could we add a case containing both a backslash and a single quote?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]