Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpFoundation] AddUrl andUrlParser#53346

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@alexandre-daubois
Copy link
Member

@alexandre-dauboisalexandre-daubois commentedJan 2, 2024
edited
Loading

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?no
Issues-
LicenseMIT

This PR#53320 raised a problem in the codebase. Each place in the code where a DSN is parsed has its own implemented logic.

This led to various consistency issues: variable names differing from one place to another but having the same meaning, different behavior (some places decode HTML characters in URLs while others don't), work done "twice"... And of course, if a bug is detected somewhere, you have to check that it's not present everywhere (as must have been done with the PR mentioned above).

@OskarStark and@nicolas-grekas raised that there could be some place for something that unifies the work of DSN parsing which is of course always the same: parse the URL, decode the auth part with special chars, check a scheme is present, check the host is optionally present also.

Here is afirst take on this. I created the logic in HttpFoundation, because why not, but I don't think this is the best place. However, we don't have any idea on where to put this as you can see in the comments of the linked PR 😄 I'm even sure that this is not the right place because, to me, add HttpFoundation as a dependency for this DSN parser feels weird.

A new component might be the solution, but it seems it was already discussed in the past and it was rejected (note that I couldn't find info about this, so if you were part of the discussion, feel free to link some issue or PR, thanks!).

This PR will give you an idea of what could be possible. I already leveraged this new mechanism in DI, Notifier, Mailer and Translation so you can see this in action. Of course, if this get accepted, the next step will be to leverage this in the Cache component mainly.

Things to discuss:

  • What are your thoughts on the API?
  • Where should we put this (new component, in an existing component, something else)?
  • Which additional feature should be bundled in Parser or Parameters?

/**
* @author Alexandre Daubois <alex.daubois@gmail.com>
*/
finalclass Parametersimplements \Stringable
Copy link
Contributor

Choose a reason for hiding this comment

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

I would still name thisàI would name this classDsn`

yield [
'some://',
'Themailer DSN is invalid.',
'The"some://" DSN is invalid.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Exposing the DSN here means it could leak sensitive data to a log file

alexandre-daubois reacted with thumbs up emoji
@xabbuh
Copy link
Member

see#32546 for a related discussion

alexandre-daubois reacted with heart emoji

@Nyholm
Copy link
Member

Here is a link to a PR I made to try introduce a DSN component.
#36999

Symfony is all about following official standards. There is no standard for DSN (believe it or not). That is why it might be hard to push for a dedicated DSN component.

alexandre-daubois reacted with heart emoji

@nicolas-grekas
Copy link
Member

💯 That's why I wrote we might need a URL parser, not a DSN parser ;)

Nyholm and welcoMattic reacted with thumbs up emoji

@alexandre-daubois
Copy link
MemberAuthor

Alright I see the distinction. A bit of renaming is needed here. An URL parser could belong to HttpFoundation, as it already has some "UrlHelper".

@OskarStark
Copy link
Contributor

Symfony is all about following official standards. There is no standard for DSN (believe it or not). That is why it might be hard to push for a dedicated DSN component.

I understand, but we created our own standard of DSN in the Symfony world, which is spread across different components

@nicolas-grekas
Copy link
Member

we created our own standard of DSN in the Symfony world

That's not the case, each DSN in Symfony is potentially adhoc for the components that need one. There are already differences that are hard to abstract.

Nyholm reacted with thumbs up emoji

@Nyholm
Copy link
Member

Symfony is all about following official standards. There is no standard for DSN (believe it or not). That is why it might be hard to push for a dedicated DSN component.

I understand, but we created our own standard of DSN in the Symfony world, which is spread across different components

Yes, that work has beenimplementation driven. I looked at how Symfony is using DSN and I created aspecification for it. But making it a dedicated component says more "This is how Symfony think DSN should work". If we are just implementing DSN in various other components means we can eat the cake and have it too (ie don't agree on a standard but use DSN as we like).

Im obviously not against a DSN component or let a official DSN parser be part of HTTPFoundation, a new URI component. Im just trying to give some background or a TLDR for#36999 and#32546.

@alexandre-daubois
Copy link
MemberAuthor

alexandre-daubois commentedJan 2, 2024
edited
Loading

There are already differences that are hard to abstract.

Would you have an example? From what I saw during therawurldecode URL, "everything" seems pretty aligned. Isn't the differences something that could be solved with some good polymorphism?

Im just trying to give some background or a TLDR

Thank you for that! 🙏

@Nyholm
Copy link
Member

Would you have an example?

It is mostly the "function" part. Some components supports DSN like:

failover(dummy://a dummy://a)failover(dummy://a,dummy://a)failover:(dummy://a,dummy://a)roundrobin(dummy://a failover(dummy://b dummy://a) dummy://b)
nicolas-grekas, alexandre-daubois, and welcoMattic reacted with thumbs up emoji

@alexandre-daubois
Copy link
MemberAuthor

Just a quick thought but shouldn't we just use Tobias' package in the framework?

Nyholm reacted with eyes emoji

@alexandre-dauboisalexandre-daubois changed the title[HttpFoundation] AddDsn\Parser andDsn\Parameters[HttpFoundation] AddUrl andUrlParserJan 2, 2024

class InvalidUrlExceptionextends \InvalidArgumentException
{
publicfunction__construct(string$dsn)
Copy link
Member

Choose a reason for hiding this comment

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

string $url ?

Copy link
Contributor

Choose a reason for hiding this comment

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

parameter can be removed IMHO

$dsn =$this->scheme.'://';

if ($this->isAuthenticated()) {
$dsn .=rawurlencode($this->user).':'.rawurlencode($this->pass).'@';
Copy link
Member

Choose a reason for hiding this comment

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

Will throw if one ofthis->user orthis->pass is null, asrawurlencode() requires a string

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Good catch 👍

publicfunction__construct(
publicstring$scheme,
public ?string$user =null,
public ?string$pass =null,
Copy link
Member

Choose a reason for hiding this comment

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

Could we usepassword here ?

OskarStark reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We could, but this would make impossible to do the following:

$url =newUrl(...parse_url($url));

This is why I keptpass here

Choose a reason for hiding this comment

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

the goal of the new code should be to completely replace using parse_url, so this argument is void sorry. (parse_url is broken)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Oh yes, of course 🤦 Updated accordingly

@welcoMattic
Copy link
Member

IsHttpFoundation the best place for such a parser? It will be used on Notifier, Translation, etc, in not necessarily HTTP request related context. I'm just back from holidays, maybe the topic has already been discussed elsewhere, but why not creating a small component namedUrlParser?

Nyholm, OskarStark, kvrushifa, and wkania reacted with thumbs up emoji

@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@alexandre-daubois
Copy link
MemberAuthor

Closed in favor ofsymfony/polyfill#498

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@OskarStarkOskarStarkOskarStark left review comments

@welcoMatticwelcoMatticAwaiting requested review from welcoMatticwelcoMattic is a code owner

@NyholmNyholmAwaiting requested review from Nyholm

+1 more reviewer

@smnandresmnandresmnandre left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

7.2

Development

Successfully merging this pull request may close these issues.

8 participants

@alexandre-daubois@xabbuh@Nyholm@nicolas-grekas@OskarStark@welcoMattic@smnandre@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp