Skip to content

Lookbehind in number regexp crashes Safari #106

@tmadeira

Description

@tmadeira

Describe the bug
The regular expression at https://github.com/scriptcoded/sql-highlight/blob/master/lib/index.js#L42 uses lookbehind, which is currently not supported by latest Safari (https://caniuse.com/js-regexp-lookbehind) and some other browsers; caniuse says that its global support is 76.9%. Safari considers that the code has a syntax error, crashing the page.

To Reproduce

  1. Import sql-highlight getSegments in your browser bundle.
  2. Load your page on Safari.
  3. Page crashes with "syntax error: invalid regular expression: invalid group specifier name".

(Or just type /((?<![a-zA-z])\d+(?:\.\d+)?)/g on Safari console.)

Expected behavior
Code should compile.

sql-highlight (please complete the following information):
v4.3.1 (latest)

Node.js (please complete the following information):
Not applicable.

Browser (please complete the following information):
MacOS Safari 16.3 (latest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions