`Resource.pointer` indexes into strings

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

还没有人认领这个 Issue。

评估

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

调研方向

从 referencing/_core.py 中的 Resource.pointer 开始,具体是 isinstance(contents, Sequence) 分支;issue 指出了确切的错误检查和预期错误。先用 snippet 复现,然后在修改 string 分支之前,确认该方法中其他地方是如何抛出 PointerToNowhere 的。检查测试套件中现有的 pointer 测试,确定应在哪里添加覆盖:对字符串使用 /name/0 会抛出错误,而不是返回 'x'。完成意味着字符串不再继续向下解析,并且非 mapping、非 sequence 的值会抛出 PointerToNowhere。

由索引模型根据 Issue 内容生成。

描述

Resource.pointer treats any collections.abc.Sequence as a JSON array, and str is a
Sequence, so a pointer can step into a string's characters. RFC 6901 §4 only descends into
objects and arrays, so this reference should not resolve.

from referencing import Registry, Resource

Resource.opaque({"name": "xyz"}).pointer("/name/0", Registry().resolver()).contents
# 'x'   (expected: PointerToNowhere)

Reproduced on referencing 0.37.0 (CPython 3.12) and on main at 45e3c7f (CPython 3.13).

The cause is the isinstance(contents, Sequence) branch in Resource.pointer
(referencing/_core.py). The open PRs #387 and #427 validate the array-token spelling inside that
branch, but a string still takes it, so /name/0 resolves with either change applied. Excluding
str from that branch, and raising PointerToNowhere when the current value is neither a mapping
nor a non-string sequence, would fix it.

主要语言
Python
星标
56
派生
55
平均合并
5 天 22 小时
30 天内合并 PR
4

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

python-jsonschema/referencing 的其他 Issue

查看 python-jsonschema/referencing 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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