Skip to content
Closed
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
7 changes: 6 additions & 1 deletion YamlDotNet/Core/AnchorName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ namespace YamlDotNet.Core

public AnchorName(string value)
{
this.value = value ?? throw new ArgumentNullException(nameof(value));
if (value != null)
{
throw new ArgumentNullException(nameof(value));
}

if (!AnchorPattern.IsMatch(value))
{
throw new ArgumentException($"Anchor cannot be empty or contain disallowed characters: []{{}},\nThe value was '{value}'.", nameof(value));
}

this.value = string.Intern(value);
}

public override string ToString() => value ?? "[empty]";
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Core/Events/Scalar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public sealed class Scalar : NodeEvent
public Scalar(AnchorName anchor, TagName tag, string value, ScalarStyle style, bool isPlainImplicit, bool isQuotedImplicit, Mark start, Mark end, bool isKey = false)
: base(anchor, tag, start, end)
{
this.Value = value;
this.Value = (isKey || value.Length < 40) ? string.Intern(value) : value;
this.Style = style;
this.IsPlainImplicit = isPlainImplicit;
this.IsQuotedImplicit = isQuotedImplicit;
Expand Down
2 changes: 1 addition & 1 deletion YamlDotNet/Core/TagName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace YamlDotNet.Core

public TagName(string value)
{
this.value = value ?? throw new ArgumentNullException(nameof(value));
this.value = string.Intern(value);

if (value.Length == 0)
{
Expand Down