Skip to content

Only strip a JSON prefix that starts at the front - #1966

Open
SashaMIT wants to merge 1 commit into
httpie:masterfrom
SashaMIT:json-prefix-match
Open

SashaMIT wants to merge 1 commit into
httpie:masterfrom
SashaMIT:json-prefix-match

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Oct 1, 2026 •

Copy link
Copy Markdown

Summary

load_prefixed_json('{{"a": 1}') returned the prefix a and the object {"a": 1}. The string is not JSON, and a is not a prefix. re.findall took a match from inside the body and cut that many characters off the front.

The search is now anchored at the start. while(1);{"a": 1} still returns the prefix while(1); and the object. {{"a": 1} raises ValueError.

Fixes #1965

Test plan

  • test_prefixed_json_does_not_chop_inside_the_body fails on tip and passes with re.match
  • test_json_formatter_with_body_preceded_by_non_json_data still passes (224 cases)

findall() treated a match inside the body as the prefix and cut that many characters off the front.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A JSON body that starts with a brace can be parsed from the middle

1 participant