potiuk opened a new pull request, #72166:
URL: https://github.com/apache/airflow/pull/72166

   ## Why
   
   `GoogleDriveHook` builds Drive search expressions by interpolating names 
directly into single-quoted string literals:
   
   ```python
   # _ensure_folders_exists
   f"name='{current_folder}'"
   f"'{current_parent}' in parents"
   
   # get_file_id
   query = f"name = '{file_name}'"
   query += f" and parents in '{folder_id}'"
   ```
   
   The Drive query language delimits string literals with single quotes and 
escapes `'` and `\` with a backslash. Neither call site escapes either 
character, so a name containing a quote ends the literal early and the 
expression stops meaning what the caller asked for.
   
   Names routinely arrive from a bucket listing rather than being typed by hand 
— a wildcard `gcs_to_gdrive` transfer passes through whatever object names the 
bucket happens to contain — so quotes in them are ordinary input, not an exotic 
case.
   
   ## What
   
   - Add `_escape_drive_query_value()` and route all four interpolations 
through it.
   - Backslashes are escaped **before** quotes, so the backslash introduced by 
the quote escape is not itself doubled.
   - Tests: a parametrised check of the escaping itself, plus two asserting the 
built `q=` expression for `get_file_id` and `_ensure_folders_exists`.
   
   A single shared helper rather than escaping at each site, since there are 
four interpolations across two methods and the next one added would otherwise 
be easy to miss.
   
   ## Compatibility
   
   No change for names without `'` or `\` — the overwhelming majority. Names 
that previously produced a malformed expression now produce a correct one.
   
   ## Testing
   
   Escaping verified locally across `plain.csv`, `o'brien.csv`, a 
backslash-containing name, and a name with an embedded quote-and-clause, 
including the backslash-ordering case.
   
   `ruff check` and `ruff format` are clean and `py_compile` passes, but **the 
provider test suite could not be executed in my environment** (an unrelated 
local editable-install problem prevented importing `airflow`), so **CI needs to 
run `providers/google`.**
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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]

Reply via email to