Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove invalidation of whitespace in TryGetNextExtendedAttribute #78465

Merged
merged 3 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,6 @@ private static bool TryGetNextExtendedAttribute(
}
line = line.Slice(spacePos + 1).TrimStart((byte)' ');

// If there are any more spaces, it's malformed.
if (line.IndexOf((byte)' ') >= 0)
{
return false;
}

// Find the equal separator.
int equalPos = line.IndexOf((byte)'=');
if (equalPos < 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,27 @@ public void ExtractGlobalExtendedAttributesEntry_Throws()
Assert.Throws<InvalidOperationException>(() => entry.ExtractToFile(Path.Join(root.Path, "file"), overwrite: true));
}
}

[Theory]
[InlineData("key", "value")]
[InlineData("key ", " value ")]
[InlineData(" key ", " value ")]
[InlineData("many sla/s\\hes", "/////////////\\\\\\///////////")]
public void GlobalExtendedAttribute_Roundtrips(string key, string value)
{
var stream = new MemoryStream();
using (var writer = new TarWriter(stream, leaveOpen: true))
{
writer.WriteEntry(new PaxGlobalExtendedAttributesTarEntry(new Dictionary<string, string>() { { key, value } }));
}

stream.Position = 0;
using (var reader = new TarReader(stream))
{
PaxGlobalExtendedAttributesTarEntry entry = Assert.IsType<PaxGlobalExtendedAttributesTarEntry>(reader.GetNextEntry());
Assert.Equal(1, entry.GlobalExtendedAttributes.Count);
Assert.Equal(KeyValuePair.Create(key.TrimStart(), value), entry.GlobalExtendedAttributes.First());
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
stephentoub marked this conversation as resolved.
Show resolved Hide resolved