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

Minimist version update #9

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

xt-riot
Copy link

@xt-riot xt-riot commented Jan 20, 2025

Fixes: mcollina/autocannon#520

Arg parsing fails if URL ends with ]:

The previous implementation was picking up inline(attached to the string supplied) brackets. This PR changes the regex that was used to end a context.

/\]$/ -> /^\[?[^\[]*\]$/

This change means that if an opening bracket is found inside the string(except the very first character), the regex returns false and therefore does not close the context.

The PR also updates the minimist dependency to 1.2.8 since there were critical vulnerabilities(namely, prototype pollution on versions <=1.2.5). I've tested autocannon to make sure the version doesnt include breaking changes, but took the liberty to bump to a major version. Feel free to change it(or comment it out so I change it) should you consider the changes not major-bump-worthy

I also took the liberty to add a .gitignore which includes only the node_modules directory.

Tests

The following tests are all returning the correct object. There's a mix between using the closing and opening brackets(used for changing contexts) directly adjacent to the string/word and having a space inbetween.

subarg('http://localhost\?q=\[1\]'.split(/\s+/))
subarg('beep -t [ boop -o a.txt -u http://localhost -u http://localhost\?q=\[1\] -q]'.split(/\s+/))
subarg('beep -t [boop -o a.txt -u http://localhost -u http://localhost\?q=\[1\] -q -o b.txt]'.split(/\s+/))
subarg('beep -t [ boop -o a.txt -u http://localhost -u http://localhost\?q=\[1\] ]'.split(/\s+/))
subarg('beep -t [boop -o a.txt -u http://localhost\?q=\[1\] -u http://localhost]'.split(/\s+/))
subarg('beep -t [ boop -o a.txt -u [beep] ]'.split(/\s+/))
subarg('beep -t [boop] -u [ be[ep] ]'.split(/\s+/))

The following tests are not working as expected. I've documented them(added the test cases, but the tests are skipped), but I think those are super edge-cases. If you think otherwise, let me know and I'll try to find a way to fix it

  1. If the user uses a string that includes a closing bracket directly adjacent of the context closing bracket, the script doesnt work. This is easily mitigated by using a space between the two, or changing the order of the arguments(ie, using the -u http://localhost at the end)
subarg('beep -t [boop -o a.txt -u http://localhost -u http://localhost\?q=\[1\]]'.split(/\s+/))

@xt-riot xt-riot force-pushed the inline-bracket-error branch from 2e2b1b2 to 2dc191b Compare January 20, 2025 16:41
@xt-riot xt-riot force-pushed the inline-bracket-error branch from 2dc191b to be8c04f Compare January 20, 2025 16:42
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

Successfully merging this pull request may close these issues.

Arg parsing fails if URL ends with ]
1 participant