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

Avoid slowdown from URL#searchParams in glob embed #94

Merged
merged 2 commits into from
Jan 19, 2024

Conversation

MattIPv4
Copy link
Member

Type of Change

  • Markdown-It Plugins: Glob embed

What issue does this relate to?

Relates to #92

What should this PR do?

URL#searchParams#append seems to have terrible performance when working with a large number of parameters, across different runtimes and browsers: https://twitter.com/MattIPv4/status/1748102513646047584 (https://twitter.com/MattIPv4/status/1748116227703099900)

While it is unlikely in regular use that the glob embed would encounter enough tests being provided for this to actually be an issue, it was reported as a potential attack vector in the library.

As such, this PR switches us over to a more old-fashioned approach of using encodeURIComponent in a loop, which shouldn't risk any drastic performance issues in such an edge case.

This also includes a minor refactor of the glob regex that was fixed in #92 so it is easier to follow what is happening in it.

What are the acceptance criteria?

Glob embeds continue to parse and generate as expected, with no performance bottleneck from the new test with a large number of tests provided.

@MattIPv4 MattIPv4 added bug Something isn't working patch Change is SEMVER patch labels Jan 18, 2024
Copy link
Contributor

@davidcarlsonberg davidcarlsonberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@MattIPv4 MattIPv4 merged commit 081867e into master Jan 19, 2024
4 checks passed
@MattIPv4 MattIPv4 deleted the MattIPv4/url-searchparams-perf branch January 19, 2024 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working patch Change is SEMVER patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants