Skip to content

Commit

Permalink
[GDrive] Escape apostrophes in search queries
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmx81 committed Aug 30, 2024
1 parent e5cfde3 commit 736172c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gdrive/provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def request_credentials(access_token=None):
raise AssertionError("No service account or oauth credentials provided")


def escape(text: str) -> str:
return text.replace("'", "\\'")


def search(query, access_token=None):
service = build("drive", "v3", credentials=request_credentials(access_token))

Expand All @@ -121,7 +125,7 @@ def search(query, access_token=None):
+ " or ".join([f"mimeType = '{mime_type}'" for mime_type in SEARCH_MIME_TYPES])
+ ")",
"("
+ " or ".join([f"fullText contains '{word}'" for word in query_words])
+ " or ".join([f"fullText contains '{escape(word)}'" for word in query_words])
+ ")",
]

Expand Down

0 comments on commit 736172c

Please sign in to comment.