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 off-by-one valueFromProviderState index #1034

Merged
merged 1 commit into from
Mar 7, 2020

Conversation

kppullin
Copy link
Contributor

PactDslJsonArray.valueFromProviderState() assigns an index
one less than it should.

Before appending to the body array,
the method invokes appendArrayIndex(), which in turn emits an
index value of body.length()-1. Since the body array is yet to
be updated the calculated index is off by one (the most obvious
sign of this is a negative index of -1).

This PR moves the append to body first.

`PactDslJsonArray.valueFromProviderState()` assigns an index
one less than it should. Before appending to the `body` array,
the method invokes `appendArrayIndex`, which in turn emits an array
index value of `body.length()-1`. Since the `body` array is yet to
be updated the calculated index is off by one (the most obvious
sign of this is a negative index of `-1`).

This PR moves the append to `body` first.
body.put(example);
generators.addGenerator(Category.BODY, rootPath + appendArrayIndex(0), new ProviderStateGenerator(expression));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option here would be to change appendArrayIndex(0) to appendArrayIndex(1). I went the proposed approach instead as it matched most other patterns in the class and it didn't appear there was any dependencies on the order of operations here.

@uglyog
Copy link
Member

uglyog commented Mar 7, 2020

Thanks for the PR! I agree with your approach being the better option.

@uglyog uglyog merged commit 981943c into pact-foundation:master Mar 7, 2020
@uglyog
Copy link
Member

uglyog commented Mar 8, 2020

Version 4.0.7 has been released with this change

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

3 participants