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

Index passed to state can sometimes be incorrect #16

Open
derek-miller opened this issue Oct 24, 2019 · 0 comments
Open

Index passed to state can sometimes be incorrect #16

derek-miller opened this issue Oct 24, 2019 · 0 comments

Comments

@derek-miller
Copy link

derek-miller commented Oct 24, 2019

Using the state param within the keep() function has the incorrect index when encountering a quote. Looking at the code, state.index = i, but then later i is changed without updating state

 $ node 
Welcome to Node.js v12.3.1.
Type ".help" for more information.
> const split = require('split-string');
undefined
> split('a\\"', {
...   separator: ' ',
...   quotes: ['"'],
...   keep: (value, state) => {
.....     console.log({
.......       value,
.......       prev: state.prev(),
.......       index: state.index,
.......       charAtIndex: state.input[state.index],
.......       input: state.input
.......     });
.....     if (state.input[state.index] !== value) {
.......       throw new Error()
.......     }
.....     return true;
.....   }
... });
{
  value: 'a',
  prev: undefined,
  index: 0,
  charAtIndex: 'a',
  input: 'a\\"'
}
{ value: '\\', prev: 'a', index: 1, charAtIndex: '\\', input: 'a\\"' }
{ value: '"', prev: '\\', index: 1, charAtIndex: '\\', input: 'a\\"' }
Thrown:
Error
    at keep (repl:13:13)
    at append (./node_modules/split-string/index.js:42:18)
    at module.exports (./node_modules/split-string/index.js:68:9)

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

No branches or pull requests

1 participant