Render Images from Data Sources Test Fix #7337
Thanks for the PR! This test is moving in the right direction but it's a bit too specific and some of it is unnecessarily complicated. Some suggestions:
- All your explicit quantifiers can either be removed (
{1}
is implied unless otherwise specified) or replaced with the?
shorthand. - Anywhere that your regex checks for a single or double quote needs to be able to accept either.
- Anywhere you check for spaces needs to accept any whitespace and you need to make sure you allow whitespace in every place where it would be valid.
- You can't assume the user will use
+=
instead of__ = __ + __
. - All your capture groups can be removed and simply be character literals.
- You don't need to do things like
(i|I)
if you use thei
flag at the end of your regex.
@ltegman
Updated RegEx
/html *(\+=) *\" *<(i|I)(m|M)(g|G) *(s|S)(r|R)(c|C) *= *'? *" *\+ *val.imageLink *\+ *" *'? *> *" *;/g
All your explicit quantifiers can either be removed ({1} is implied unless otherwise specified) or replaced with the ? shorthand.
Can you give specific place where this issues arises in the aforementioned(I think that's the right use of this word...) RegEx
I think I've fixed this is the RegEx at the top of this comment.
Anywhere that your regex checks for a single or double quote needs to be able to accept either.
The main issue I found trying to do this was that it would require checking if the begining quotes where double or single cause mixing them incorrectly won't work.
Anywhere you check for spaces needs to accept any white space and you need to make sure you allow white space in every place where it would be valid.
I've updated the RegEx to work with something like the following(In concern to white space.)
html += " <img src = ' " + val.imageLink + " ' > " ;
You can't assume the user will use += instead of __ = __ + __
Uhm..... Ok, will have to look more into this piece.
You don't need to do things like (i|I) if you use the i flag at the end of your regex.
The issue I ran into with the 'i' flag was that, "val.imageLink" needs to be case-sensitive or else it won't actually render the images.
Updates the test for completion on Render Images from Data Sources to be somewhat more strict.
And this has been tested on a local version of FCC.