yourlabs/django-autocomplete-light

Invalid regular expression error in Safari

vpotter opened this issue · 11 comments

Version: 3.8.2
Error: SyntaxError: Invalid regular expression: invalid group specifier name

return !this.id.match(/(?<!-\d+)-empty-(?!\d+-)/);

The error is caused by a look-behind regex assertion which is not supported by Safari (according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#browser_compatibility)

The error is reproducible on both desktop & mobile.

jpic commented

Can someone find a regex that works with safari and suggest it here?

@jpic Any development on this?

I've read the comment, but since I've never used django-nested-admin I'm not sure I get it right.

What type of id's you'd like to exclude among the following:

100-empty-200
x-empty-y
test100-empty-1test
foo-100-empty-200-bar

What if we simpy check it like this: https://regex101.com/r/R8FLpq/1 ?

Or 2 expressions one to check if there no match for <digits>-empty-<digits> AND there is match for -empty-

It breaks Safari for us as well :(

progl commented

but I reverting to 3.8.1 - it is good with safari

If I understand the comments right:

  • -empty- should return false
  • -foo-empty-bar- should return false
  • -1-empty-2- should return true
  • -foo-bar- should return true
// return !this.id.match(/(?<!-\d+)-empty-(?!\d+-)/);
return !this.id.match(/-empty-/) || this.id.match(/-\d+-empty-\d+-/);
  • -empty- matches the left side, is negated by the !, and fails to match the right side, so the whole expression is false
  • -foo-empty-bar- matches the left side, is negated by the !, and fails to match the right side, so again, false
  • -1-empty-2- matches the left side, is negated by the !, and then does match the right side, so the whole expression is true
  • -foo-bar- doesn't match the left side, so gets negated to true by the !, and the expression shortcircuits returning true

I replaced the Ajax version from 3.8.1 to resolve the issue

Any chance that a new version will be released soon to PyPI with this fix included?
At the moment DAL is non-functional in Safari browsers (both desktop and mobile) for me.

jpic commented

Sure, anyone can confirm the current master is working in production for them?

It works for me!

(Safari 14.1 on macOS, and whatever the latest Safari is on iOS)

jpic commented