Skip to content

Fix ErrorWithPosition panic when less than two lines - #433

Closed
xoltia wants to merge 3 commits into
BurntSushi:masterfrom
xoltia:master
Closed

xoltia wants to merge 3 commits into
BurntSushi:masterfrom
xoltia:master

Conversation

@xoltia

@xoltia xoltia commented Nov 22, 2024

Copy link
Copy Markdown
Contributor

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.

Comment thread error_test.go Outdated
|
| At line 0, column 14:
|
| 0 | string = "test

Copy link
Copy Markdown
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
Copy Markdown
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.

@arp242

arp242 commented Mar 17, 2025

Copy link
Copy Markdown
Collaborator

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.

2 participants