firestore: field path with a quoted name ending in a backslash is misparsed
维护者通常 1 天内回复
评估
调研方向
从 google/cloud/firestore_v1/field_path.py 开始,检查 FieldPath.from_api_repr() 使用的 QUOTED 令牌模式;使用提供的 FieldPath 示例重现故障。检查字段路径解析器测试,并添加对以反斜杠结尾且后接另一个片段的带引号片段的覆盖。完成标准是 API 表示能够解析回原始各部分,并且更新指向 issue 中描述的嵌套字段。
由索引模型根据 Issue 内容生成。
描述
Package: google-cloud-firestore (google/cloud/firestore_v1/field_path.py), current main.
What happens
FieldPath.to_api_repr() escapes a trailing backslash correctly, but the parser cannot read the result back when another quoted segment follows it. FieldPath.from_api_repr() raises ValueError, and FieldPath.from_string() catches that error and falls back to a plain split on ., so it silently returns parts that still contain the backticks and escape characters.
Because update() and set(..., merge=[...]) go through FieldPath.from_string() / parse_field_path(), the write goes to the wrong field.
Minimal repro
from google.cloud.firestore_v1.field_path import FieldPath
from google.cloud.firestore_v1 import _helpers
s = FieldPath("dir\\", "file name").to_api_repr()
print(s) # `dir\\`.`file name`
print(FieldPath.from_string(s).parts) # ('`dir\\\\`', '`file name`')
FieldPath.from_api_repr(s) # ValueError: Invalid path
pbs = _helpers.pbs_for_update("projects/p/databases/d/documents/c/doc", {s: 1}, None)
print(list(pbs[0].update.fields)) # ['`dir\\\\`']
What should happen
The string produced by to_api_repr() should parse back to the same parts, ('dir\\', 'file name'), and the update should target dir\ > file name.
Root cause
The QUOTED token pattern is r"`(?:\\`|[^`])*?`". In `dir\\`.`file name` the lazy match takes the second backslash together with the closing backtick as an escaped backtick (\`), so the token runs on to the next backtick and swallows `.`. What remains (file name`) does not tokenize, so parsing fails. The pattern needs to treat a backslash as an escape for the next character, not only for a backtick, and should not let a bare backslash match on its own.
- 主要语言
- Python
- 星标
- 5.4k
- 派生
- 1.8k
- 平均合并
- 2 天 1 小时
- 30 天内合并 PR
- 191
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/google-cloud-python 的其他 Issue
-
api: spanner type: feature request
难度 2/5 1-3 小时 新手友好度 68/100
googleapis/google-cloud-python#18584 ·
维护者通常 1 天内回复
-
auth: call_client_cert_callback() discards passphrase for encrypted keys可能已有人在做 @kwy404 于 18 天前认领。 未关闭
难度 1/5 1-3 小时 新手友好度 92/100
googleapis/google-cloud-python#18467 ·
维护者通常 1 天内回复
-
auth: `impersonated_credentials` loses `subject` on copy, so `with_scopes()` and `with_quota_project()` turn off domain wide delegation可能已有人在做 @Om-singhaI 于 30 天前认领。 未关闭auth priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 88/100
googleapis/google-cloud-python#18428 ·
维护者通常 1 天内回复
-
priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 72/100
googleapis/google-cloud-python#18375 · 1 条评论 ·
维护者通常 1 天内回复
-
ci: enable --strict flag in presubmit twine_check可能已有人在做 @ohmayr 于 19 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 76/100
googleapis/google-cloud-python#18339 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 googleapis/google-cloud-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
eclipse-score/inc_someip_gateway#356 ·
维护者通常 2 天内回复
-
[BUG]: `GitHubRestAdapter.check_user_permission` and `has_write_access` raise `TypeError` (missing `params`), silently disabling the inactivity lifecycle可能已有人在做 @tarunagnihotri534 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 67/100
AOSSIE-Org/Gitcord-GithubDiscordBot#167 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
mihai-vlc/sublime-jsfmt#56 ·
-
comp/cli comp/plugins P2 type/bug
难度 2/5 1-3 小时 新手友好度 75/100
NousResearch/hermes-agent#141917 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 78/100
riscv/riscv-opcodes#441 ·