1
0
Fork 0
mirror of synced 2024-09-30 00:57:16 +13:00

Fix for safari, removing all usage of regex lookbehinds.

This commit is contained in:
mike12345567 2022-02-15 14:48:32 +00:00
parent b421ddf60b
commit 676ec02380
3 changed files with 21 additions and 6 deletions

View file

@ -41,8 +41,6 @@
"@spectrum-css/vars": "^3.0.1",
"apexcharts": "^3.22.1",
"dayjs": "^1.10.5",
"fs-extra": "^8.1.0",
"jsdom": "^16.0.1",
"postcss": "^8.2.10",
"rollup": "^2.44.0",
"rollup-plugin-json": "^4.0.0",

View file

@ -3,7 +3,7 @@ const { registerAll, registerMinimum } = require("./helpers/index")
const processors = require("./processors")
const { atob, btoa } = require("./utilities")
const manifest = require("../manifest.json")
const { FIND_HBS_REGEX, FIND_DOUBLE_HBS_REGEX } = require("./utilities")
const { FIND_HBS_REGEX, findDoubleHbsInstances } = require("./utilities")
const hbsInstance = handlebars.create()
registerAll(hbsInstance)
@ -135,8 +135,7 @@ module.exports.processStringSync = (string, context, opts) => {
* @param string the string to have double HBS statements converted to triple.
*/
module.exports.disableEscaping = string => {
let regexp = new RegExp(FIND_DOUBLE_HBS_REGEX)
const matches = string.match(regexp)
const matches = findDoubleHbsInstances(string)
if (matches == null) {
return string
}

View file

@ -1,7 +1,25 @@
const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g
module.exports.FIND_HBS_REGEX = /{{([^{].*?)}}/g
module.exports.FIND_DOUBLE_HBS_REGEX = /(?<!{){{[^{}]+}}(?!})/g
module.exports.FIND_TRIPLE_HBS_REGEX = /{{{([^{].*?)}}}/g
// originally this could be done with a single regex using look behinds
// but safari does not support this feature
// original regex: /(?<!{){{[^{}]+}}(?!})/g
module.exports.findDoubleHbsInstances = string => {
let copied = string
const doubleRegex = new RegExp(exports.FIND_HBS_REGEX)
const regex = new RegExp(exports.FIND_TRIPLE_HBS_REGEX)
const tripleMatches = copied.match(regex)
// remove triple braces
if (tripleMatches) {
tripleMatches.forEach(match => {
copied = copied.replace(match, "")
})
}
const doubleMatches = copied.match(doubleRegex)
return doubleMatches ? doubleMatches : []
}
module.exports.isAlphaNumeric = char => {
return char.match(ALPHA_NUMERIC_REGEX)