Skip to content

[4.x] Make Json::getRaw() return an unfiltered value and add getRawBody() - #60

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-json-getraw-name
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-json-getraw-name

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Input documents getRaw($name, $default) as the accessor for an unfiltered value (via __call()), but Json declares a real getRaw() that returns the raw request body. So $input->json->getRaw('field') ignores its arguments and returns the whole body, or null when the data was passed to the constructor: (new Json(['field' => 'value']))->getRaw('field') === null. An unfiltered JSON field can only be read with get('field', null, 'raw').

This change:

  • adds Json::getRawBody(), which returns the raw body (null if the data was passed to the constructor);
  • makes getRaw(?string $name = null, mixed $default = null) return the unfiltered value when a name is given, like on every other input;
  • keeps getRaw() without a name returning the body for BC, with a deprecation pointing to getRawBody(). In 5.0 that variant goes away.

Subclasses of Json that override getRaw() without parameters become incompatible with the new signature. I do not know of any.

Testing Instructions

New tests in JsonTest: testGetRawWithName() and testGetRawWithoutNameIsDeprecated() fail before the change; testGetRawBodyWithSource() covers the new method. The existing testgetRaw() (body via the deprecated call) still passes.

Documentation Changes Required

docs/overview.md ("JSON bodies"): getRaw('name'), getRawBody() and the deprecation of the no-argument call.

🤖 Generated with Claude Code

Input documents getRaw($name, $default) as the accessor for an unfiltered
value, but Json declares a real getRaw() that returns the request body, so
$input->json->getRaw('field') ignored its arguments and returned the whole
body (or null when the data was passed in). An unfiltered JSON field could
not be read through the documented API.

getRaw() now returns the unfiltered value when a name is given. Called
without a name it still returns the body, but that is deprecated in favour
of the new getRawBody().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant