Skip to content

Remove implicit ext-json dependency#4325

Closed
BenMorel wants to merge 1 commit intodoctrine:masterfrom
BenMorel:json
Closed

Remove implicit ext-json dependency#4325
BenMorel wants to merge 1 commit intodoctrine:masterfrom
BenMorel:json

Conversation

@BenMorel
Copy link
Copy Markdown
Contributor

@BenMorel BenMorel commented Oct 5, 2020

Q A
Type improvement
BC Break no
Fixed issues none

Summary

The codebase contains calls to json_encode(), yet this is not documented in the requirements.

The json extension can be disabled in PHP 7!

@morozov
Copy link
Copy Markdown
Member

morozov commented Oct 5, 2020

The JSON extension is used in literally a couple of places of which only the usage for the JSON type is really justified. This doesn't look like a good reason to make it a core dependency. I'd rather rework the Exception class to not depend on it. As for the JSON type, its usage is optional, so it doesn't necessitate adding the dependency IMO (same as there's no dependency on any of the DB drivers).

@BenMorel
Copy link
Copy Markdown
Contributor Author

BenMorel commented Oct 6, 2020

This doesn't look like a good reason to make it a core dependency. I'd rather rework the Exception class to not depend on it.

I agree, but as it stands, it is a core dependency at the moment, due to this usage. I'll try to refactor the Exception class then. Leaving this issue open until then.

@BenMorel BenMorel changed the title Add missing ext-json requirement Remove implicit ext-json requirement Oct 6, 2020
@BenMorel
Copy link
Copy Markdown
Contributor Author

BenMorel commented Oct 6, 2020

OK, I actually did it in this PR. Ready for review, @morozov!

This would maybe benefit from being moved to a separate class, like ParameterFormatter?

@BenMorel BenMorel changed the title Remove implicit ext-json requirement Remove implicit ext-json dependency Oct 6, 2020
}

if (is_scalar($param)) {
if (is_string($param) && (! $this->isValidUTF8($param) || $this->containsNonPrintableASCIIChars($param))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After sleeping on it, I'm not sure if DBAL should be in the business of formatting prepared statement parameters at all.

The responsibility of the exception is to tell what went wrong by its error message and encapsulate the context for future handling or troubleshooting. By imprinting prepared statement parameters into the message, it may do a disservice: it makes it impossible to log the error message w/o logging the potentially sensitive information stored in the exception context (e.g. tokens, password hashes, personally identifiable information, etc).

Let's try to explore the approach of storing the parameters with the exception w/o making them part of the message. This way, the handling part will be free to process them in an appropriate way (e.g. ignore all parameters except for passwords and tokens) or ignore them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prototype available in #4387!

@GrahamCampbell
Copy link
Copy Markdown

GrahamCampbell commented Oct 10, 2020

This should probably target 2.11.x? EDIT: 2.12.x?

@morozov
Copy link
Copy Markdown
Member

morozov commented Nov 1, 2020

Closing in favor of #4387.

@morozov morozov closed this Nov 1, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants