Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

firestore: field path with a quoted name ending in a backslash is misparsed

未关闭 适合新手
#18,771 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@auraseb 已经在做这个了。

开始于 2026年10月19日。

  • #18772 来自 @auraseb —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend, databases

调研方向

从 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

googleapis/google-cloud-python 的其他 Issue

查看 googleapis/google-cloud-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。