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

[FrameworkBundle] Fix a regression in handling absolute template paths#17894

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

Merged

Conversation

@jakzal
Copy link
Contributor

QA
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#17777#17683
LicenseMIT
Doc PR-

Regression introduced by#15272.

}

if (!preg_match('/^(?:([^:]*):)?(?:([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/',$name,$matches)) {
if (!preg_match('/^(?:([^:]*):([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/',$name,$matches) ||$this->isAbsolute($name)) {
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Two groups replaced with one here. This will only match "Foo:Bar:" or "".

@jakzal
Copy link
ContributorAuthor

@francoispluchino@wesleylancel would you mind checking if this fixes your issues please?

@francoispluchino
Copy link
Contributor

@jakzal It's OK for me! Thank you for this PR.

@jakzal
Copy link
ContributorAuthor

I just confirmed it also fixes the issue reported by@Congelli501. Waiting for@wesleylancel to either confirm his case's fixed, or to provide a failing scenario.

@fabpot
Copy link
Member

Not really related to this PR, but loading templates via an absolute path looks terrible.

@francoispluchino
Copy link
Contributor

@fabpot I agree with you if you load a template from a Bundle or App Resources, but when the template file is generated dynamically, and it is not in a Bundle we have no other choice.

Personally, I have this problem with the mail templates that are accessible via a custom stream, with the email generator that provided me the absolute path of the template. So, dynamically add the template file before loading the template is not very subtle, Because thetemplating.locator will search the template, while the path is already known ...

Of course, I am interested by best practices, if you have any.

@jakzal
Copy link
ContributorAuthor

Back to the topic... I confirmed wesleylancel's problem still persists. I'll work on a fix this afternoon.

@jakzal
Copy link
ContributorAuthor

@hcomnetworkers can you try this patch please?

status: needs review

@hcomnetworkers
Copy link

@jakzal I have tested your patch and it works for#17958, thank you!

@jakzal
Copy link
ContributorAuthor

Several people confirmed this fixes the issue for them.

status: reviewed

return$this->cache[$name] =$template;
}

privatefunctionisAbsolute($path)
Copy link
Member

Choose a reason for hiding this comment

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

Can you rename toisAbsolutePath() as this is the name we are using elsewhere.

Also, I'd prefer to use a more restrictive approach like done elsewhere:

privatefunctionisAbsolutePath($file)    {return$file[0] ==='/' ||$file[0] ==='\\'            || (strlen($file) >3 &&ctype_alpha($file[0])                &&$file[1] ===':'                && ($file[2] ==='\\' ||$file[2] ==='/')            );    }

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This won't work with windows paths which are "normalised" for some reasons here:

$name =str_replace(':/',':',preg_replace('#/{2,}#','/',str_replace('\\','/',$name)));

C:\\path\\to\\section\\name:foo.html.php becomesC:path/to/section/name:foo.html.php. I really don't know what's this for.

@jakzaljakzalforce-pushed thetemplate-name-parser-regression branch fromde3d770 tofe1f5d2CompareMarch 3, 2016 07:43
@jakzaljakzalforce-pushed thetemplate-name-parser-regression branch fromfe1f5d2 tod8c493fCompareMarch 3, 2016 08:16
@fabpot
Copy link
Member

Thank you@jakzal.

@fabpotfabpot merged commitd8c493f intosymfony:2.3Mar 3, 2016
fabpot added a commit that referenced this pull requestMar 3, 2016
…mplate paths (jakzal)This PR was merged into the 2.3 branch.Discussion----------[FrameworkBundle] Fix a regression in handling absolute template paths| Q             | A| ------------- | ---| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#17777#17683| License       | MIT| Doc PR        | -Regression introduced by#15272.Commits-------d8c493f [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths
@stof
Copy link
Member

stof commentedMar 3, 2016

but when the template file is generated dynamically, and it is not in a Bundle we have no other choice.

The right way to do this would be to come up with your own convention about template names and a template loader able to resolve it. Seehttps://github.com/Behat/Borg/blob/2d8422d006b32cff929a0e475acb473258911baf/src/Integration/Symfony/Documentation/Twig/DocumentationLoader.php for an example doing it

@fabpot@jakzal what do you think about deprecating the possibility to use absolute paths ? AFAIK, this was never intended to work. It was just a side-effect of the initial implementation.

@fabpot
Copy link
Member

@stof Indeed, it works by chance. We should definitely deprecate this. see#17999

@jakzal
Copy link
ContributorAuthor

@stof indeed looks like many cases were supported unintentionally. Since there was no test cases for them I wasn't sure if it was intended. I'll send a PR to deprecated absolute paths.

@jakzaljakzal deleted the template-name-parser-regression branchMarch 4, 2016 09:04
@fabpotfabpot mentioned this pull requestMar 13, 2016
This was referencedMar 25, 2016
thrownew \RuntimeException(sprintf('Template name "%s" contains invalid characters.',$name));
}

if (!preg_match('/^(?:([^:]*):)?(?:([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/',$name,$matches)) {

Choose a reason for hiding this comment

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

That breaks FooBundle:Post/file.html.twig pattern

prathje reacted with thumbs up emojicjean-fr and jverdeyen reacted with confused emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

8 participants

@jakzal@francoispluchino@fabpot@hcomnetworkers@stof@cjean-fr@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp