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: zero-based index #735

Merged

Conversation

golergka
Copy link
Contributor

What does this PR do?

My project uses yaml-language-server, and I got these errors in Sentry:

Error: Range#create called with invalid arguments[1682, -1, 1682, 0]
4    at Object.e.create
5  at Object.e.create
6  at Zl.getLineCharCode

Unfortunately, I wasn't able to reproduce this error, so all my work is just following the stacktrace.

What issues does this PR fix or reference?

The only place where the function getLineCharCode is used is here:

for (let j = 0, lenJ = currentLineLength; j < lenJ; j++) {
const charCode = useCurrentLineText ? currentLineText.charCodeAt(j) : source.getLineCharCode(lineNumber, j);

Both surrounding code and description on charCodeAt suggest that this index should be 0-based, but the getLineCharCode is written with a 1-based index in mind, which seems like the source of this bug.

Is it tested? How?

I wasn't able to reproduce the original issue, so it's hard for me to test this fix.

@coveralls
Copy link

coveralls commented Jun 24, 2022

Coverage Status

Coverage remained the same at 82.58% when pulling 9fe98e8 on golergka:fix/zero-based-index into eae5206 on redhat-developer:main.

Copy link
Collaborator

@evidolob evidolob left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@msivasubramaniaan msivasubramaniaan left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants