Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser fails to parse links which are not valid regex #753

Open
haynesgt opened this issue May 16, 2024 · 0 comments
Open

Parser fails to parse links which are not valid regex #753

haynesgt opened this issue May 16, 2024 · 0 comments

Comments

@haynesgt
Copy link

Expected Behavior

Should be able to Parser.parse("https://ahrefs.com/jobs/clickhouse-c++-developer")

Current Behavior

SyntaxError: Invalid regular expression: /^https://ahrefs.com/jobs/clickhouse-c++-developer/i: Nothing to repeat
    at new RegExp (<anonymous>)
    at makeBaseRegex (node_modules/@postlight/parser/dist/mercury.js:7403:10)
    at scoreLinks (node_modules/@postlight/parser/dist/mercury.js:7419:19)

Steps to Reproduce

await (Parser = require("@postlight/parser")).parse("https://ahrefs.com/jobs/clickhouse-c++-developer")

Detailed Description

Issue in 2.2.3

return new RegExp(`^${baseUrl}`, 'i');

Possible Solution

function makeBaseRegex(baseUrl) {
  var escapedUrl = baseUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  return new RegExp(`^${escapedUrl}`), 'i');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant