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
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?

};

const subStrFrom = (val, startFromVal) => {
const dataPosition = val.indexOf(startFromVal);
return val.substr(dataPosition);
return val.substring(dataPosition);
};

const isJsonRequest = parsedCommand => (parsedCommand.headers[contentTypeHeader] &&
Expand Down Expand Up @@ -56,7 +56,7 @@ const parseQueryStrings = (url) => {
const queryStrings = {};
if (paramPosition !== -1) {
// const splitUrl = parsedCommand.url.substr(0, paramPosition);
const paramsString = url.substr(paramPosition + 1);
const paramsString = url.substring(paramPosition + 1);
const params = paramsString.split('&') || [];

params.forEach((param) => {
Expand Down