ParamQuery grid support forum

General Category => Bug Report => Topic started by: jplevene on November 25, 2024, 06:15:50 pm

Title: Safari 16 and below bug with suggested fix
Post by: jplevene on November 25, 2024, 06:15:50 pm
In pqgrid.dev.js from 3212:

Code: [Select]
/*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;
});

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.
Title: Re: Safari 16 and below bug with suggested fix
Post by: jplevene on November 25, 2024, 07:58:26 pm
Just to add, this is serious as v10.1.0 will not load on Safari 16 or below because of this.
Title: Re: Safari 16 and below bug with suggested fix
Post by: paramvir on May 28, 2025, 08:44:13 am
The original code uses a negative lookbehind

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

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

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