Skip to content
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

[WebProfilerBundle] Fix regexp #14217

Closed
wants to merge 3 commits into from
Closed

[WebProfilerBundle] Fix regexp #14217

wants to merge 3 commits into from

Conversation

mykiwi
Copy link
Contributor

@mykiwi mykiwi commented Apr 5, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #12122
License MIT
Doc PR

Old PR #12124

@javiereguiluz
Copy link
Member

@romqin thanks a lot for fixing this annoying issue!

@aitboudad
Copy link
Contributor

👍 indeed I wonder how to make it work with absolute URL ?

@mykiwi
Copy link
Contributor Author

mykiwi commented Apr 5, 2015

@aitboudad what if I add this :

+ var path = url.substr({{ app.request.basePath|length }});
- if (url.substr(0, 1) === '/' && !url.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {
+ if (path.substr(0, 1) === '/' && !path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {

@aitboudad
Copy link
Contributor

@romqin

- var path = url.substr({{ app.request.basePath|length }});
+ var path = url.replace('{{ app.request.schemeAndHttpHost }}', '');

@mykiwi
Copy link
Contributor Author

mykiwi commented Apr 5, 2015

Or this, but maybe it's overkill :

var path = url;
if (url.substr(0, 1) === '/') {
    if (0 === url.indexOf('{{ app.request.getBasePath }}')) {
        path = url.substr({{ app.request.basePath|length }});
    }
}
else if (0 === url.indexOf('{{ app.request.getSchemeAndHttpHost() ~ app.request.getBasePath }}')) {
    path = url.substr({{ (app.request.getSchemeAndHttpHost() ~ app.request.basePath)|length }});
}

if (!path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {

@aitboudad
Copy link
Contributor

look good but I'd prefer to use replace instead of substr to simplify code :)

var path = (url.substr(0, 1) === '/') ? url.replace('{{ app.request.basePath }}', ''):url.replace('{{ app.request.schemeAndHttpHost ~ app.request.basePath }}', '');
if (path.substr(0, 1) === '/' && !path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {

@flobb
Copy link

flobb commented Apr 7, 2015

👍

@stof
Copy link
Member

stof commented Apr 7, 2015

@aitboudad the issue with replace is that it will not only replace at the beginning of the string

@aitboudad
Copy link
Contributor

@stof no it will replace only the first occurrence.

@stof
Copy link
Member

stof commented Apr 7, 2015

@aitboudad but what if the path is not found at the beginning, but is found later in the string ?

@aitboudad
Copy link
Contributor

@stof got it

-  ? url.replace('{{ app.request.basePath }}', '')
-  : url.replace('{{ app.request.schemeAndHttpHost ~ app.request.basePath }}', '');
+  ? url.replace(/^({{ app.request.basePath|e('js') }})/, '')
+  : url.replace(/^({{ (app.request.schemeAndHttpHost ~ app.request.basePath)|e('js') }})/, '');

is that ok ?

@stof
Copy link
Member

stof commented Apr 7, 2015

@aitboudad no. you need to escape the path for a usage into a regex (especially given that / is the delimiter, and it appears in the path)

@stof
Copy link
Member

stof commented Apr 7, 2015

@romqin this looks like the right solution (except the escaping needed to output the value as a JS string)

@mykiwi
Copy link
Contributor Author

mykiwi commented Apr 7, 2015

Like this ?

var path = url;
if (url.substr(0, 1) === '/') {
    if (0 === url.indexOf('{{ app.request.basePath|e('js') }}')) {
        path = url.substr({{ app.request.basePath|length }});
    }
}
else if (0 === url.indexOf('{{ (app.request.schemeAndHttpHost ~ app.request.basePath)|e('js') }}')) {
    path = url.substr({{ (app.request.schemeAndHttpHost ~ app.request.basePath)|length }});
}

if (!path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {

@aitboudad
Copy link
Contributor

@romqin now it work for all url, you need check path.substr(0, 1) === '/' also

if (path.substr(0, 1) === '/' && !path.match(new RegExp({{ excluded_ajax_paths|json_encode|raw }}))) {

@mykiwi
Copy link
Contributor Author

mykiwi commented Apr 10, 2015

Would be great to have this fix in 2.7 beta1
ping @stof @fabpot @aitboudad @javiereguiluz

@fabpot
Copy link
Member

fabpot commented May 16, 2015

Thank you @romqin.

fabpot added a commit that referenced this pull request May 16, 2015
This PR was squashed before being merged into the 2.6 branch (closes #14217).

Discussion
----------

[WebProfilerBundle] Fix regexp

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #12122
| License       | MIT
| Doc PR        |

Old PR #12124

Commits
-------

091b37e [WebProfilerBundle] Fix regexp
@fabpot fabpot closed this May 16, 2015
@mrohnstock
Copy link
Contributor

@fabpot this PR broke Silex-WebProfiler ~2.0@dev, see silexphp/Silex-WebProfiler#64

@stof
Copy link
Member

stof commented May 29, 2015

We should not use the app global in the profiler template

fabpot added a commit that referenced this pull request May 29, 2015
…tes (stof)

This PR was merged into the 2.6 branch.

Discussion
----------

Avoid using the app global variable in the profiler templates

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | small one for people overwriting the WebDebugToolbarListener methods
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | silexphp/Silex-WebProfiler#64
| License       | MIT
| Doc PR        | n/a

#14217 introduced a usage of the ``app`` global variables in profiler templates, while we previously removed all such usages to avoid the dependency on TwigBundle in these templates.
This keeps them usable outside the fullstack framework (for instance in Silex).

I had to do a small BC break to be able to pass the request in the place where we were not yet injecting the Request in the template.

Commits
-------

415c79e Avoid using the app global variable in the profiler templates
ostrolucky pushed a commit to ostrolucky/symfony that referenced this pull request Mar 25, 2018
This PR was squashed before being merged into the 2.6 branch (closes symfony#14217).

Discussion
----------

[WebProfilerBundle] Fix regexp

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony#12122
| License       | MIT
| Doc PR        |

Old PR symfony#12124

Commits
-------

091b37e [WebProfilerBundle] Fix regexp
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.

None yet

7 participants