Closed danoc closed 3 years ago
Hello!
I think the regex on this line isn't working as intended:
https://github.com/twopluszero/next-images/blob/3095b206c804c205f101ac8c01c6c3ca8f9c4093/index.js#L24
In particular, the \. doesn't require that the file extension start with a period.
\.
Here's an example.
const extensions = ["png", "jpg", "jpeg", "gif", "ico", "image\\.svg"]; const regex = new RegExp(`\.(${extensions.join('|')})$`) console.log(regex.test("foo.png")); // true, correct behavior console.log(regex.test("foo.svg")); // false, correct behavior console.log(regex.test("foo_image.svg")); // true, **incorrect behavior** console.log(regex.test("foo.image.svg")); // true, correct behavior
Notice how foo_image.svg is considered a match even though there's an underscore, not a period, before the word image.
foo_image.svg
image
The issue goes away if another forward slash is added to the RegExp line as such:
new RegExp(`\\.(${extensions.join('|')})$`)
I'd be happy to send a PR if you'd like! 🙇🏻
Hey @danoc, that would be nice :) Thank you!
Hello!
I think the regex on this line isn't working as intended:
https://github.com/twopluszero/next-images/blob/3095b206c804c205f101ac8c01c6c3ca8f9c4093/index.js#L24
In particular, the
\.
doesn't require that the file extension start with a period.Here's an example.
Notice how
foo_image.svg
is considered a match even though there's an underscore, not a period, before the wordimage
.The issue goes away if another forward slash is added to the RegExp line as such:
I'd be happy to send a PR if you'd like! 🙇🏻