Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Yamlify.SourceGenerator/YamlSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ private static void GenerateReadMethod(StringBuilder sb, TypeToGenerate type, IR

sb.AppendLine(" if (reader.TokenType != YamlTokenType.MappingStart)");
sb.AppendLine(" {");
sb.AppendLine(" // Skip unexpected token to prevent infinite loops when reading collections");
sb.AppendLine(" reader.Skip();");
sb.AppendLine(" return default;");
sb.AppendLine(" }");
sb.AppendLine();
Expand Down Expand Up @@ -2819,6 +2821,8 @@ private static void GenerateRootCollectionRead(StringBuilder sb, ITypeSymbol col

sb.AppendLine(" if (reader.TokenType != YamlTokenType.SequenceStart)");
sb.AppendLine(" {");
sb.AppendLine(" // Skip unexpected token to prevent infinite loops when reading collections");
sb.AppendLine(" reader.Skip();");
sb.AppendLine(" return default;");
sb.AppendLine(" }");
sb.AppendLine();
Expand Down Expand Up @@ -2860,6 +2864,8 @@ private static void GenerateRootDictionaryRead(StringBuilder sb, ITypeSymbol dic

sb.AppendLine(" if (reader.TokenType != YamlTokenType.MappingStart)");
sb.AppendLine(" {");
sb.AppendLine(" // Skip unexpected token to prevent infinite loops when reading collections");
sb.AppendLine(" reader.Skip();");
sb.AppendLine(" return default;");
sb.AppendLine(" }");
sb.AppendLine();
Expand Down
7 changes: 7 additions & 0 deletions src/Yamlify/Reader/Utf8YamlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,13 @@ public void Skip()
// Keep reading until we exit the current depth
}
}
else if (_tokenType is YamlTokenType.Scalar)
{
// For scalar values (including nulls like ~, null, Null, NULL), just advance to the next token
Read();
}
// For other tokens (end markers, etc.), do nothing - they're structural tokens
// that don't need to be skipped
}
}

Expand Down
Loading