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 ErrorWithPosition panic when less than two lines #433

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

Conversation

xoltia
Copy link

@xoltia xoltia commented Nov 22, 2024

Currently, it is possible for ParserError.ErrorWithPosition to cause a panic for some input.
You can reproduce the panic using this example:

v := &struct{ String string }{}
_, err := toml.Decode(`string = "test`, v)
parseErr := err.(toml.ParseError)
_ = parseErr.ErrorWithUsage()

I've added a fix and a new test case which covers this error.

error_test.go Outdated
|
| At line 0, column 14:
|
| 0 | string = "test
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is line 1, not 0.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I didn't notice that. I've updated the test and believe I found where the line number was being incorrectly set to 0.

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.

2 participants