Skip to content

RegExp is too greedy #8

@Jamie0

Description

@Jamie0

The RegExp used to match tags are too greedy. If the source file has, for example, multiple link or script tags on the same line, you'll often get garbage output. As a result, inline-scripts won't run on something built by preact/webpack.

For sure RegExp isn't really the best way to parse HTML, but I was able to make following change (.* to [^>]*), which seems to work around this issue.

const linkTagRegex = /<link (?:[^>]* )?rel="stylesheet"(?:[^>]* )?href="([\w.\-\/]+)"[^>]*>|<link (?:[^>]* )?href="([\w.\-\/]+)"(?:[^>]* )?rel="stylesheet"[^>]*>/;

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