Skip to content

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

Merged
derrabus merged 2 commits intodoctrine:4.2.xfrom
TimWolla:dsn-parser-quoted
Apr 9, 2025
Merged

Only trim the leading slash from the DSN if a host is also available#6790
derrabus merged 2 commits intodoctrine:4.2.xfrom
TimWolla:dsn-parser-quoted

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 #6789
@morozov morozov requested a review from derrabus February 17, 2025 15:07
`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