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

Errors with protocol-relative URLS (e.g. <img src="//example.com/image.jpg">) #27

Open
nfriedly opened this issue Jul 16, 2024 · 4 comments

Comments

@nfriedly
Copy link
Contributor

nfriedly commented Jul 16, 2024

I had one old html file in my site with the following bit:

<img alt="Fork me on GitHub" src="//s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" style="position: absolute; top: 0pt; right: 0pt; border: 0pt none;">

That url is now dead, but the error that eleventy-plugin-img2picture gave me is:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble writing to "_site/stuff/swfstore-example/index.html" from "./src/stuff/swfstore-example/index.html" (via EleventyTemplateError)
[11ty] 2. Transform `img2picture` encountered an error when transforming ./src/stuff/swfstore-example/index.html. (via EleventyTransformError)
[11ty] 3. ENOENT: no such file or directory, stat 'src/s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png' (via Error)
[11ty] 
[11ty] Original error stack trace: Error: ENOENT: no such file or directory, stat 'src/s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png'
[11ty]     at Object.stat (node:internal/fs/sync:58:25)
[11ty]     at Object.statSync (node:fs:1669:17)
[11ty]     at Image.getInMemoryCacheKey (/config/workspace/nfriedly.com/node_modules/eleventy-plugin-img2picture/node_modules/@11ty/eleventy-img/img.js:159:32)
[11ty]     at queueImage (/config/workspace/nfriedly.com/node_modules/eleventy-plugin-img2picture/node_modules/@11ty/eleventy-img/img.js:683:15)
[11ty]     at generateImage (/config/workspace/nfriedly.com/node_modules/eleventy-plugin-img2picture/lib/img2picture.js:186:26)
[11ty]     at replaceImages (/config/workspace/nfriedly.com/node_modules/eleventy-plugin-img2picture/lib/img2picture.js:256:21)
[11ty]     at Object.<anonymous> (/config/workspace/nfriedly.com/node_modules/eleventy-plugin-img2picture/lib/img2picture.js:281:14)
[11ty]     at Object.<anonymous> (/config/workspace/nfriedly.com/node_modules/@11ty/eleventy/src/BenchmarkGroup.js:32:26)
[11ty]     at Template.runTransforms (/config/workspace/nfriedly.com/node_modules/@11ty/eleventy/src/Template.js:514:30)
[11ty]     at Template.renderPageEntry (/config/workspace/nfriedly.com/node_modules/@11ty/eleventy/src/Template.js:799:26)

That ENOENT: no such file or directory, stat 'src/s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png' is the wrong error for a remote URL - I believe it's not recognizing the // at the beginning as a protocol-relative URL and therfore trying to treat it as a local file. (I have eleventyInputDir: 'src' in my config.)

These are fairly rare these days, but they are still valid. The browser just makes it either http or https, whichever the page is.

Running new URL('//example.com/image.jpg') will throw, because it doesn't have enough context to know if it should use http or https. However, these work in a img src attribute, because the browser has that context.

@nfriedly nfriedly changed the title isRemoteURL() fails for protocol-relative URLS (e.g. <img src="//example.com/image.jpg">) Errors with protocol-relative URLS (e.g. <img src="//example.com/image.jpg">) Jul 16, 2024
@saneef
Copy link
Owner

saneef commented Jul 17, 2024

The isRemoteURL() function was based on the same function from eleventy-img project. Even if I allow schema relative URLs in this plugin, it will fail down the pipeline, as I'm using eleventy-img to the processing.

I'll file an issue in the eleventy-img project, and see their response.

Copy link

stale bot commented Aug 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Aug 16, 2024
@nfriedly
Copy link
Contributor Author

I think this is still an issue

@saneef saneef removed the wontfix This will not be worked on label Aug 20, 2024
Copy link

stale bot commented Sep 20, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Sep 20, 2024
@stale stale bot closed this as completed Sep 28, 2024
@saneef saneef reopened this Sep 28, 2024
@saneef saneef removed the wontfix This will not be worked on label Sep 28, 2024
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

No branches or pull requests

2 participants