Author Topic: Safari 16 and below bug with suggested fix  (Read 6928 times)

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 149
    • View Profile
Safari 16 and below bug with suggested fix
« 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.

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 149
    • View Profile
Re: Safari 16 and below bug with suggested fix
« Reply #1 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.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6397
    • View Profile
Re: Safari 16 and below bug with suggested fix
« Reply #2 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 );
});
« Last Edit: May 28, 2025, 09:31:49 am by paramvir »