Skip to content

Only trim the leading slash from the DSN if a host is also available #6790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025

Conversation

TimWolla
Copy link
Contributor

Q A
Type improvement
Fixed issues #6789

Summary

Previously the DsnParser unconditionally removed the first character from the path, without verifying that it is actually a slash and that it is dealing with a reasonably well-formed URI. This causes confusing behavior when a malformed URI that survives parse_url() is passed to parse(), since DsnParser would return the input as the dbname, but with the first character missing.

This can lead to hard-to-debug situations when the DSN is coming from an environment variable, where quoting characters are accidentally included in the value itself, instead of being interpreted by the tool setting the env, since the dbname almost looks like the intended input (but still having the trailing quote).

see #6789

Previously the DsnParser unconditionally removed the first character from the
path, without verifying that it is actually a slash and that it is dealing with
a reasonably well-formed URI. This causes confusing behavior when a malformed
URI that survives `parse_url()` is passed to `parse()`, since DsnParser would
return the input as the `dbname`, but with the first character missing.

This can lead to hard-to-debug situations when the DSN is coming from an
environment variable, where quoting characters are accidentally included in the
value itself, instead of being interpreted by the tool setting the env, since
the `dbname` almost looks like the intended input (but still having the
trailing quote).

see doctrine#6789
`normalizeDatabaseUrlPath()` is only ever called if a `host` is available,
which means that the path needs to start with a slash. Replace the `if()` by an
`assert()` to satisfy Codecov.
@derrabus derrabus added this to the 4.2.4 milestone Apr 9, 2025
@derrabus derrabus merged commit 3004e93 into doctrine:4.2.x Apr 9, 2025
66 checks passed
@TimWolla TimWolla deleted the dsn-parser-quoted branch April 9, 2025 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants