1
1
Fork
You've already forked vdf-reader
1

Fail to parse a vdf file when a value string start with "[{" and end with "]" #2

Closed
opened 2025年12月30日 23:11:42 +01:00 by charles66820 · 1 comment

Hello,

When i parse a .vdf file with a string that begin with "[{" and end with "]" i got a NoValidToken error.
I created a reproducer (provided bellow).
This bug occurs when i want to ignore some fields, "foo1" and "foo2" in my example.
When only "foo2" is ignored everything work, but when "foo1" is ignore i got the NoValidToken error.
I observe the same thing with "foo1" "[{bar1]".

The bug don't occur when the field "foo1" is parsed as a string.

Error

called `Result::unwrap()` on an `Err` value: NoValidToken(NoValidTokenError { err_span: SourceSpan { offset: SourceOffset(38), length: 1 }, expected: [Item, QuotedItem, Statement, QuotedStatement, GroupEnd], src: "\n \"foo\" \"bar\"\n \"foo1\" \"[{]\"\n \"foo2\" \"bar2\"\n " })

Reproducer

useserde::Deserialize;usevdf_reader::from_str;#[derive(Debug, Deserialize)]#[allow(dead_code)]struct Test{foo: String,// foo1: String, /* NOTE: comment this line to produce the bug */
}fn main(){letfile_content=r#"
 "foo" "bar"
 "foo1" "[{]"
 "foo2" "bar2"
 "#;letoutput: Test=from_str(&file_content).unwrap();println!("label: {}",output.foo);}
Hello, When i parse a `.vdf` file with a string that begin with "[{" and end with "]" i got a NoValidToken error. I created a reproducer (provided bellow). This bug occurs when i want to ignore some fields, `"foo1"` and `"foo2"` in my example. When only `"foo2"` is ignored everything work, but when `"foo1"` is ignore i got the NoValidToken error. I observe the same thing with `"foo1" "[{bar1]"`. The bug don't occur when the field `"foo1"` is parsed as a string. ## Error ```txt called `Result::unwrap()` on an `Err` value: NoValidToken(NoValidTokenError { err_span: SourceSpan { offset: SourceOffset(38), length: 1 }, expected: [Item, QuotedItem, Statement, QuotedStatement, GroupEnd], src: "\n \"foo\" \"bar\"\n \"foo1\" \"[{]\"\n \"foo2\" \"bar2\"\n " }) ``` ## Reproducer ```rs use serde::Deserialize; use vdf_reader::from_str; #[derive(Debug, Deserialize)] #[allow(dead_code)] struct Test { foo: String, // foo1: String, /* NOTE: comment this line to produce the bug */ } fn main() { let file_content = r#" "foo" "bar" "foo1" "[{]" "foo2" "bar2" "#; let output: Test = from_str(&file_content).unwrap(); println!("label: {}", output.foo); } ```

Fixed with 0.3.3

Fixed with 0.3.3
Sign in to join this conversation.
No Branch/Tag specified
main
No results found.
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
icewind/vdf-reader#2
Reference in a new issue
icewind/vdf-reader
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?