Skip to content

Support keys larger > 1024 characters - #965

Merged
EdwardCooke merged 3 commits into
YamlDotNet:masterfrom
EdwardCooke:ec-bigkey
Sep 1, 2024
Merged

EdwardCooke merged 3 commits into
YamlDotNet:masterfrom
EdwardCooke:ec-bigkey

Conversation

@EdwardCooke

@EdwardCooke EdwardCooke commented Sep 1, 2024 •

Copy link
Copy Markdown
Collaborator

Fixes #942
To use, new up the scanner and specify the overriden maximum key length, when deserializing use the scanner. Here is an example:

[Fact]
public void SupportRealyLongStrings()
{
    var longKey = string.Concat(Enumerable.Repeat("x", 1500));
    var yamlString = $"{longKey}: value";
    var scanner = new Scanner(new StringReader(yamlString), true, 1500);
    var parser = new Parser(scanner);
    var deserializer = new DeserializerBuilder().Build();
    var yaml = deserializer.Deserialize<Dictionary<string, object>>(parser);
    Assert.Equal(longKey, yaml.Keys.First());
}

@EdwardCooke
EdwardCooke merged commit 03f0e59 into YamlDotNet:master Sep 1, 2024
@mvarendorff2

Copy link
Copy Markdown

Hey there, thanks so much for this change! Quick question because I might be missing something: Passing the scanner as argument to .Deserialize as shown in the snippet above causes a compiler error for me (.Deserialize only takes string, TextReader or IParser as arguments). I updated to 16.1.0.

@EdwardCooke

Copy link
Copy Markdown
Collaborator Author

I missed a line in my example. You have to new up a parser and pass that in. I’ll update the example shortly.

@EdwardCooke

Copy link
Copy Markdown
Collaborator Author

Updated.

@mvarendorff2

Copy link
Copy Markdown

Brilliant, thank you so much!

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.

Support keys longer than 1024 characters

2 participants