General Category > Bug Report

Safari 16 and below bug with suggested fix

(1/1)

jplevene:
In pqgrid.dev.js from 3212:


--- Code: ---/*BUG*/
//fmtPart = fmtPart.replace(/(?<![ap])m{1,5}/gi, replacer("M"));
/*SUGGESTED FIX*/
fmtPart = fmtPart.replace(/(?:^|[^ap])m{1,5}/gi, function (match, offset, string) {
// Ensure the match doesn't follow 'a' or 'p'
if (offset === 0 || !/[ap]/i.test(string[offset - 1])) {
return replacer("M")(match);
}
return match;
});
--- End code ---

Safari 16 does not accept the regex "/(?<![ap])m{1,5}/gi" because it does not support "<"

Please confirm the suggested fix is OK, if not, please tell me what it should be replaced with.

jplevene:
Just to add, this is serious as v10.1.0 will not load on Safari 16 or below because of this.

paramvir:
The original code uses a negative lookbehind


--- Code: ---fmtPart = fmtPart.replace(/(?<![ap])m{1,5}/gi, replacer("M"));.

--- End code ---

The following snippet can be used instead, as it avoids lookbehind by capturing the preceding character:


--- Code: ---fmtPart = fmtPart.replace(/(^|[^ap])(m{1,5})/gi, (match, prefix, mSequence, offset) => {
     return prefix + replacer('M')(mSequence, offset + prefix.length );
});

--- End code ---

Navigation

[0] Message Index

Go to full version