Repository navigation
fix(firestore): parse quoted field path names that end in a backslash #18772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,6 +59,10 @@ def test__tokenize_field_path_w_dotted_escaped(): | |||||||||
| _expect_tokenize_field_path("_0.`1`.`+2`", ["_0", ".", "`1`", ".", "`+2`"]) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test__tokenize_field_path_w_quoted_trailing_escaped_backslash(): | ||||||||||
| _expect_tokenize_field_path(r"`a\\`.`b c`", [r"`a\\`", ".", "`b c`"]) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test__tokenize_field_path_w_unconsumed_characters(): | ||||||||||
| from google.cloud.firestore_v1 import field_path | ||||||||||
|
|
||||||||||
|
|
@@ -150,6 +154,12 @@ def test_parse_field_path_w_escaped_backslash(): | |||||||||
| assert field_path.parse_field_path("`a\\\\b`.c.d") == ["a\\b", "c", "d"] | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_parse_field_path_w_trailing_escaped_backslash(): | ||||||||||
| from google.cloud.firestore_v1 import field_path | ||||||||||
|
|
||||||||||
| assert field_path.parse_field_path("`a\\\\`.`b c`") == ["a\\", "b c"] | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_parse_field_path_w_first_name_escaped_wo_closing_backtick(): | ||||||||||
| from google.cloud.firestore_v1 import field_path | ||||||||||
|
|
||||||||||
|
|
@@ -451,6 +461,14 @@ def test_fieldpath_from_string_w_non_ascii_dotted(): | |||||||||
| assert field_path.parts == ("a", "一") | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_fieldpath_from_string_w_trailing_escaped_backslash(): | ||||||||||
| from google.cloud.firestore_v1 import field_path | ||||||||||
|
|
||||||||||
| path_string = field_path.FieldPath("a\\", "b c").to_api_repr() | ||||||||||
| field_path = field_path.FieldPath.from_string(path_string) | ||||||||||
| assert field_path.parts == ("a\\", "b c") | ||||||||||
|
Comment on lines
+468
to
+469
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reassigning the variable Consider renaming the variable to
Suggested change
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_fieldpath___hash___w_single_part(): | ||||||||||
| field_path = _make_field_path("a") | ||||||||||
| assert hash(field_path) == hash("a") | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern uses
\.to match escaped characters. However, in Python, the.character does not match newlines (\n) by default unless there.DOTALLflag is active. If a field path contains an escaped newline, this pattern will fail to match.To ensure robustness and handle any escaped character (including newlines) regardless of compilation flags, use
\\[\s\S]instead of\..