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

fix(buildURL): ensure operation is idempotent #168

Merged
merged 3 commits into from
Oct 6, 2020
Merged

Conversation

ericdeansanchez
Copy link
Contributor

@ericdeansanchez ericdeansanchez commented Oct 1, 2020

The purpose of this PR is to ensure the buildSrcSet operation is
idempotent. Prior to this PR, code modified the input-parameters,
params, causing identical calls to buildSrcSet to produce different
results.

Now, the input params are copied into a new queryParams object and
this object is passed to callers requiring params. A test has been
written to show that the behavior has changed from the behavior detailed
in issue #158––the input params object remains unchanged after calling
buildSrcSet and that calling buildSrcSet multiple times produces
the same result (given the same inputs).

I also ripgrep'd through the repo with rg 'params.[:alpha:]' and with
rg 'params\[' to ensure params is never mutated (i.e. it never
appears on the left hand side of any expression).

Tests have been added to ensure that _buildParams:

  • does not modify its input-argument

Tests have been added to ensure that calling buildURL:

  • is an idempotent operation with empty args
  • is an idempotent operation with args
  • does not modify empty args
  • does not modify its args (non-empty)

Tests have been added to ensure that buildSrcSet:

  • does not modify input params and is idempotent

Closes #158

Copy link
Contributor

@frederickfogerty frederickfogerty left a comment

Choose a reason for hiding this comment

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

Looks good overall! Good work @ericdeansanchez!

test/test-buildSrcSet.js Show resolved Hide resolved
test/test-buildURL.js Outdated Show resolved Hide resolved
test/test-buildURL.js Outdated Show resolved Hide resolved
test/test-buildURL.js Show resolved Hide resolved
test/test-buildURL.js Show resolved Hide resolved
src/imgix-core-js.js Show resolved Hide resolved
@ericdeansanchez ericdeansanchez merged commit b111d38 into main Oct 6, 2020
@ericdeansanchez ericdeansanchez deleted the fix-buildURL branch October 6, 2020 17:45
@ericdeansanchez
Copy link
Contributor Author

🎉 This PR is included in version 0.3.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

buildSrcSet mutates params argument when building either fluid or fixed-width srcset.
3 participants