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(static): url encoded name included in generated ext #340

Merged
merged 4 commits into from
Jun 29, 2021

Conversation

btkostner
Copy link
Contributor

@btkostner btkostner commented Jun 25, 2021

This fixes an issue with the static provider on remote domains including query params in the nuxt generate filename outputs.

Example

Say I have domains: ['https://images.prismic.io'] in my nuxt config and passing an src like https://images.prismic.io/blog-system76/30e9de39-20a6-4caf-8728-0ec917942a0f_tumblr_4fef1ab602684355ef9596a0b9fdb122_810bfad7_1280.png?auto=compress,format&rect=56,0,700,700&w=800&h=800, the generated nuxt image file path would end up looking like dist/_nuxt/image/181d93.png%3Fauto=compress,format&rect=56,0,700,700&w=800&h=800.

This PR changes it to output dist/_nuxt/image/181d93.png by stripping anything after %3F which is the url encoded ?

@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2021

Codecov Report

Merging #340 (b44d891) into main (d9aeae2) will decrease coverage by 0.55%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #340      +/-   ##
==========================================
- Coverage   59.36%   58.81%   -0.56%     
==========================================
  Files          26       26              
  Lines         598      607       +9     
  Branches      149      190      +41     
==========================================
+ Hits          355      357       +2     
- Misses        243      250       +7     
Impacted Files Coverage Δ
src/generate.ts 3.57% <0.00%> (ø)
src/runtime/image.ts 66.37% <0.00%> (-1.52%) ⬇️
src/utils.ts 64.28% <0.00%> (-35.72%) ⬇️
src/module.ts 92.85% <0.00%> (-3.30%) ⬇️
src/runtime/providers/vercel.ts 0.00% <0.00%> (ø)
src/provider.ts 74.28% <0.00%> (+2.06%) ⬆️
src/runtime/providers/ipx.ts 100.00% <0.00%> (+15.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d9aeae2...b44d891. Read the comment docs.

@btkostner
Copy link
Contributor Author

An alternative solution for this is to loop over a list of known good formats ('.png', .jpg') and use '.startsWith()' on the ext string.

@pi0
Copy link
Member

pi0 commented Jun 29, 2021

Thanks for PR @btkostner. I've added a refactor to pass original src (input) to mapToStatic that we can use extracting name and ext before passed to provider without encoding issues. Also added a guessExt utility partially implementing your second idea to validate guessed ext against a simple regex.

@pi0 pi0 changed the title fix: url encoded name included in generated ext fix(static): url encoded name included in generated ext Jun 29, 2021
@btkostner
Copy link
Contributor Author

@pi0 Looks good! I wasn't sure how to add a test for this, but doing npm link confirms that this fixes my issue 🎊

@pi0 pi0 merged commit 58dd744 into nuxt:main Jun 29, 2021
@pi0
Copy link
Member

pi0 commented Jun 29, 2021

Thanks for confarming. Will trigger release after adding few more fixes.

@btkostner btkostner deleted the filename-format branch June 29, 2021 17:46
procrates pushed a commit to procrates/nuxt-image that referenced this pull request Feb 21, 2023
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
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.

3 participants