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

Should filter $params against available manipulations/params #336

Open
midweste opened this issue Oct 29, 2021 · 2 comments
Open

Should filter $params against available manipulations/params #336

midweste opened this issue Oct 29, 2021 · 2 comments

Comments

@midweste
Copy link

midweste commented Oct 29, 2021

Great package! I'm building a wordpress implementation of glide (will share when finished) and I've found what I consider is a slight bug in the handling of query string manipulations.

I think params should be filtered by defined params because any arbitrary query string variables will create new images

<img src="/img/users/myimage.jpg?w=300&h=400&fit=crop">
<img src="/img/users/myimage.jpg?w=300&h=400&fit=crop&asdf=asdf">
<img src="/img/users/myimage.jpg?w=300&h=400&fit=crop&qwer=qwer">

Will all create new images, technically they should be the same image as the additional query string variables do not constitute a new variant. Currently three cache images are created and I'm assuming that has to do with the name of cache files being a hash of the parameters.

Just a quick couple quick functions/methods for filtering below (minimally tested). I haven't got into the source yet to see where this would need to go, but when I do I'll try and put in a pull request.

function getQueryStringManipulationsAllowed(): array
{
    // https://glide.thephpleague.com/2.0/api/quick-reference/
    return [
        'or',
        'flip',
        'crop',
        'w',
        'h',
        'fit',
        'dpr',
        'bri',
        'con',
        'gam',
        'sharp',
        'blur',
        'pixel',
        'filt',
        'mark',
        'markw',
        'markh',
        'markx',
        'marky',
        'markpad',
        'markpos',
        'markalpha',
        'bg',
        'border',
        'q',
        'fm',
    ];
}

// this method would need any other qs variables accepted!!
function getQueryStringOther(): array
{
    return [
        'p', // preset
        's', // security signature
    ];
}

function getQueryStringFiltered(array $params): array
{
    $merged = array_merge(getQueryStringManipulationsAllowed(), getQueryStringOther());
    return array_intersect_key($params, array_flip($merged));
}
@ADmad
Copy link
Collaborator

ADmad commented Jan 4, 2022

@midweste Still interested in making that pull request? 🙂

@midweste
Copy link
Author

@ADmad Yes! Will try to put one in this week :)

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

No branches or pull requests

2 participants