Literals which are unquoted strings not being verified for JSON syntax

未关闭
#229 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
compilers

调研方向

从提供的 Python 脚本和 jmespath.search() 入口点开始,然后将实现处理字面量表达式的方式与链接的 JMESPath literal-expressions 规范进行比较。确认未加引号的字面量内容是否必须产生语法错误,并使用 wat、3 以及 `{"foo": bar}” 这样的用例验证其行为。

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

描述

My understanding based on the specification is that the content of a literal expression, i.e. the text between backticks, is supposed to be a valid JSON expression, otherwise it should be reported as a syntax error. The Python implementation seems to be treating them as strings instead, though. For example, this is accepted as a valid JMESPath expression:

thing == `wat`

even though I would think it should cause an error. Is this an actual bug in the Python implementation, or have I been misunderstanding the spec? (In the latter case I'd argue that the spec is misleading about this to the point of it being a documentation bug, but that's a separate issue.)

Here's a short script that demonstrates the error:

import jmespath, json, sys

literal_json = 'wat'
expression = f"thing == `{literal_json}`"
document = {"thing": "wat"}

try:
    r = json.loads(literal_json)
except Exception as e:
    print(f"json: parse error: {e.__class__.__name__}")
else:
    print("json: no parse error")
    print(f"  result: {r!r}")

try:
    r = jmespath.search(expression, document)
except Exception as e:
    print(f"jmespath: parse error: {e.__class__.__name__}")
else:
    print("jmespath: no parse error")
    print(f"  result: {r!r}")

It prints out the following:

$ python test-jmespath.py 
json: parse error: JSONDecodeError
jmespath: no parse error
  result: True

I would expect to see the jmespath part of the output be the same as the json part of the output, i.e. some kind of parsing error. And if I try other kinds of values, I do indeed get consistent results. For example, replacing the literal_json assignment line with literal_json = '3' gives

$ python test-jmespath.py 
json: no parse error
result: 3
jmespath: no parse error
result: False

and if I replace it with literal_json = '{"foo": bar}' I get

$ python test-jmespath.py 
json: parse error: JSONDecodeError
jmespath: parse error: LexerError
主要语言
Python
星标
2.5k
派生
231
PR 合并指标
30 天内没有已合并 PR

环境准备

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

从这里开始

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

jmespath/jmespath.py 的其他 Issue

查看 jmespath/jmespath.py 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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