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

Closed
wants to merge 3 commits into from

Conversation

xoltia
Copy link
Contributor

@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
Contributor 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.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@arp242
Copy link
Collaborator

arp242 commented Mar 17, 2025

Merged via 4664468; thanks!

@arp242 arp242 closed this Mar 17, 2025
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

2 participants