Literals which are unquoted strings not being verified for JSON syntax

Aperta
#229 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
compilers

Direzione di ricerca

Inizia dallo script Python fornito e dall’entry point jmespath.search(), quindi confronta il modo in cui l’implementazione gestisce le espressioni letterali con la specifica JMESPath collegata per literal-expressions. Verifica se i contenuti letterali non racchiusi tra virgolette devono produrre un errore di sintassi e verifica il comportamento con casi come wat, 3 e `{"foo": bar}”.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
2.5k
Fork
231
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jmespath/jmespath.py

Tutte le issue di jmespath/jmespath.py

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.