build/generate-sri.js doesn't work if single-quotes are used in config.yml
Created by: Noah2610
We use a fork of bootstrap for our design system, and we just noticed (and fixed) a bug regarding the build/generate-sri.js
script.
The script is supposed to replace all SRI hashes in config.yml
, where the hashes are wrapped in "
(double-quotes). In our project we use '
(single-quotes), and the script doesn't work correctly with single-quotes; it replaces ALL values wrapped in single-quotes, with each generated hash.
Our solution requires some regular expression tweaking: https://github.com/twbs/bootstrap/blob/master/build/generate-sri.js#L58
sh.sed(
'-i',
new RegExp(`(\\s*${file.configPropertyName}:\\s*("|\'))(\\S*)(("|\'))`),
// NOTE: Using capture groups 1 and 4, because there are multiple,
// smaller capture groups used, for the "|' or-ing to work properly.
`$1${integrity}$4`,
configFile
)
Here we wrap the "|'
"or"-ing in capture groups, which fixes the issue.
We then also need to adjust the used capture group number in the replacement part of the function call ($3 -> $4
).
(I also made the whitespace matching a bit more generous, using *
instead of +
, not sure if this is a good idea.)
I have not tested this extensively, but this fixes the issue for us. Somebody may want to look at this regular expression again, or use (a reviewed version of) our RegExp.
Tested on node.js versions:
- v12.13.0
- v10.15.3