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

Bug in regular expression matching assets #12

Open
uuf6429 opened this issue Aug 4, 2022 · 0 comments
Open

Bug in regular expression matching assets #12

uuf6429 opened this issue Aug 4, 2022 · 0 comments

Comments

@uuf6429
Copy link

uuf6429 commented Aug 4, 2022

const assets_regex = new RegExp(`(\\"((http)?s?:?(\\/?\\/[^"]*.(${this.settings.import_assets.types.join('|')})))(\\\\)?")`, "g")

If we look at that regular expression, it basically boils down to something like:

<snip> [^"]*.(jpg|png|pdf <snip> ) <snip>

That dot/period looks suspicious - why do we care that there is at least one character before the file extension?
I am guessing that the intention there was to match a literal dot (as in .png) and not "any character" (as in *png), in which case it should have been escaped like \. (but should be escaped twice in that string: \\.).

In general, that code looks like it works, but it also matches things like https://somesite.com/amazing-blog-about-png. This leads to errors later on, in my case something like so (I still don't fully understand the reason behind error, but the regex fix should fix it):
image

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

1 participant