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

REQUEST_URI in default context #123

Closed
asacarter opened this issue May 14, 2019 · 4 comments · Fixed by #151
Closed

REQUEST_URI in default context #123

asacarter opened this issue May 14, 2019 · 4 comments · Fixed by #151
Assignees
Labels

Comments

@asacarter
Copy link

Since updating the library, REQUEST_URI is no longer available in the default context but is referred to within the Pagination tag.

Is this the correct or should it be set manually?

@sanmai
Copy link
Collaborator

sanmai commented May 14, 2019

Does not seem like correct. I'll be looking into this.

@sanmai sanmai added the bug label May 14, 2019
@sanmai sanmai self-assigned this May 14, 2019
@shawngoh87
Copy link

More information:
v1.4.12 broke pagination urls due to #116 (the patch to fix content injection in $_SERVER)

Setting EXPOSE_SERVER = true fixes the problem.

@sanmai @asacarter should we have a whitelist instead of a blanket ban on $_SERVER variables?

@shawngoh87
Copy link

Here's a quick workaround filter that patches the problem:

$template->registerFilter('patch_pagination_url', function ($pagination_url) {
    if (filter_var($pagination_url, FILTER_VALIDATE_URL)) {
        return $pagination_url;
    }
    // Broken URL due to missing REQUEST_URI in context
    // e.g. http://?page=2
    // Naive fix assuming that there's exactly one query param
    $page = explode('=', $pagination_url)[1];

    $url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http")
        . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

    $url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?')
        . \Liquid\Liquid::get('PAGINATION_CONTEXT_KEY') . '=' . $page;

    return $url;
});

Usage:

{{ paginate products by 6 }}
Next URL: {{ paginate.next.url | patch_pagination_url }}
{{ endpaginate }}

@sanmai
Copy link
Collaborator

sanmai commented Jun 20, 2021

I have nothing against an allow-list of sorts. Care to make a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants