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

fix: change substr() to substring() #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Cerchie
Copy link

@Cerchie Cerchie commented Mar 7, 2022

I've been reading your code, thank you for it! 😄

I noticed that it uses substr() which has been deprecated.
I updated with substring() which should be an adequate replacement if you agree.

I didn't notice any ways set up to write tests in the repo, but I'd be happy to provide some if needed.

This PR includes:

  • changes to src/index.js.

src/index.js Outdated
@@ -19,12 +19,12 @@ const isDataOption = str => isMatchingOption(['--data ', '--data-ascii ', '-d ',
const removeLeadingTrailingQuotes = (str) => {
const quotes = ['\'', '"'];
const newStr = str.trim();
return quotes.includes(newStr[0]) ? newStr.substr(1, newStr.length - 2) : newStr;
return quotes.includes(newStr[0]) ? newStr.substring(1, newStr.length - 2) : newStr;

Choose a reason for hiding this comment

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

substr's second parameter is length based. substring's is offset based.
This means that if the first parameter is 0 then there is no difference when converting but in this case it's 1 which can't be converted by just replacing the function name.
The right code in this case would be
newStr.substring(1, newStr.length - 1)

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for reviewing! I added your suggestion in the latest commit.

Copy link
Author

Choose a reason for hiding this comment

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

Circling back here -- ok to merge?

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.

None yet

2 participants