Symptom
Sync fails for individual files with HttpError 400 ... "Invalid Value", e.g.: This is a file name with 'apostrophes'.pdf
Error
<HttpError 400 when requesting .../files?q=%271weJUiVGs...%27+in+parents+and+name+%3D+%27Ich+gebe+%27250602_kLiq... returned "Invalid Value". Details: [{'reason': 'invalid', 'location': 'q', ...}]
Root Cause
GDriveConnector._find_file() in connectors/gdrive.py builds the Drive API query
via an f-string and interpolates both the folder segment (segment) and the
filename (search_name) without any escaping:
q=f"'{current_folder}' in parents and name = '{segment}' and mimeType = '...folder' and trashed = false"
q=f"'{current_folder}' in parents and name = '{search_name}' and trashed = false"
If the filename itself contains a ', it breaks the Drive API v3 query syntax,
since ' is used there as the string delimiter.
Fix
Added an escape helper and applied it at both call sites:
def _escape_drive_query_value(value: str) -> str:
"""Escape a value for safe use inside a Drive API v3 query string."""
return value.replace("\\", "\\\\").replace("'", "\\'")
segment and search_name are now passed through _escape_drive_query_value()
before being interpolated into the query. folder_id/current_folder (Drive IDs)
don't need escaping since they're never user-supplied free text.
Verification
Symptom
Sync fails for individual files with
HttpError 400 ... "Invalid Value", e.g.:This is a file name with 'apostrophes'.pdfError
<HttpError 400 when requesting .../files?q=%271weJUiVGs...%27+in+parents+and+name+%3D+%27Ich+gebe+%27250602_kLiq... returned "Invalid Value". Details: [{'reason': 'invalid', 'location': 'q', ...}]
Root Cause
GDriveConnector._find_file()inconnectors/gdrive.pybuilds the Drive API queryvia an f-string and interpolates both the folder segment (
segment) and thefilename (
search_name) without any escaping:If the filename itself contains a
', it breaks the Drive API v3 query syntax,since
'is used there as the string delimiter.Fix
Added an escape helper and applied it at both call sites:
segmentandsearch_nameare now passed through_escape_drive_query_value()before being interpolated into the query.
folder_id/current_folder(Drive IDs)don't need escaping since they're never user-supplied free text.
Verification
Invalid Value/400 Bad Requesterrors forfiles with an apostrophe in the name
Ich gebe '...' für Sie frei.pdf) importssuccessfully