Understood. It’s odd you’re getting an undefined error when you use regular HTML tags.
From what’s been investigated so far, @cpytel’s guess that the isWebPFile
function validation of what’s a WebP file and what’s not needs to be tweaked with a more comprehensive test seems like the way to go towards solving this
The best way I can imagine is doing a regular expression that does a match
for files to contain .webp
after any amount of letters and numbers like [-A-Za-z]+
.
Forgetting to take account bad naming conventions are possible by a user, I would say the best regular expression to use instead of the substring test would be
if (a.match(/[\w.\-\s]+(?=\.)+\.webp/ig))
#may need to use the !! in this situation, not sure whether or not match returns false or null :/
# Edit (9:48pm): Seems I have to use the literal syntax's .text method.
I still have to read PaperClip’s documentation on how to manipulate Paperclip’s process of changing file_names when files get uploaded to remove spaces from file names of course…
Checking my expression inside of Lea Verou’s and Cody Lindley’s Regular Expression Playgrounds (the latter can be found here) with no problems, hopefully such an expression solves the filename gotcha concerning finger-printed .webp files when I attend to it later tonight.
To Clarify One Aspect About My Regular Expression
Making sure I took account spaces, I also made sure to take account additional periods before the .webP file extension; especially to match against file names like the following:
<img src="some_stupid_filename-with_crappy_naming-conventions.dragonborn.webp?dragonborn=true" alt="I was made by a fool" />