-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[release/7.0] Fix prefix writing on TarHeaderWrite #75373
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
Changes from all commits
64af359
bac54fa
63b9158
7c407ee
04d14e5
a2d1aa5
fe1d82e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ | |||||
|
||||||
using System.Collections.Generic; | ||||||
using System.IO; | ||||||
using System.Linq; | ||||||
using Xunit; | ||||||
|
||||||
namespace System.Formats.Tar.Tests | ||||||
|
@@ -299,5 +300,57 @@ public void WriteTimestampsBeyondOctalLimit(TarEntryFormat format) | |||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
[Theory] | ||||||
[InlineData(TarEntryFormat.V7)] | ||||||
// [InlineData(TarEntryFormat.Ustar)] https://github.com/dotnet/runtime/issues/75360 | ||||||
[InlineData(TarEntryFormat.Pax)] | ||||||
[InlineData(TarEntryFormat.Gnu)] | ||||||
public void WriteLongName(TarEntryFormat format) | ||||||
{ | ||||||
var r = new Random(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this would have a seed. That way the test is reproducible.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glad you used 42. It's the answer to life, the universe, and everything. 😃 |
||||||
foreach (int length in new[] { 99, 100, 101, 199, 200, 201, 254, 255, 256 }) | ||||||
{ | ||||||
string name = string.Concat(Enumerable.Range(0, length).Select(_ => (char)('a' + r.Next(26)))); | ||||||
WriteLongNameCore(format, name); | ||||||
} | ||||||
} | ||||||
|
||||||
private void WriteLongNameCore(TarEntryFormat format, string maxPathComponent) | ||||||
{ | ||||||
TarEntry entry; | ||||||
MemoryStream ms = new(); | ||||||
using (TarWriter writer = new(ms, true)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
TarEntryType entryType = format == TarEntryFormat.V7 ? TarEntryType.V7RegularFile : TarEntryType.RegularFile; | ||||||
entry = InvokeTarEntryCreationConstructor(format, entryType, maxPathComponent); | ||||||
writer.WriteEntry(entry); | ||||||
|
||||||
entry = InvokeTarEntryCreationConstructor(format, entryType, Path.Join(maxPathComponent, maxPathComponent)); | ||||||
writer.WriteEntry(entry); | ||||||
} | ||||||
|
||||||
ms.Position = 0; | ||||||
using TarReader reader = new(ms); | ||||||
|
||||||
entry = reader.GetNextEntry(); | ||||||
string expectedName = GetExpectedNameForFormat(format, maxPathComponent); | ||||||
Assert.Equal(expectedName, entry.Name); | ||||||
|
||||||
entry = reader.GetNextEntry(); | ||||||
expectedName = GetExpectedNameForFormat(format, Path.Join(maxPathComponent, maxPathComponent)); | ||||||
Assert.Equal(expectedName, entry.Name); | ||||||
|
||||||
Assert.Null(reader.GetNextEntry()); | ||||||
|
||||||
string GetExpectedNameForFormat(TarEntryFormat format, string expectedName) | ||||||
{ | ||||||
if (format is TarEntryFormat.V7 && expectedName.Length > 100) // V7 truncates names at 100 characters. | ||||||
{ | ||||||
return expectedName.Substring(0, 100); | ||||||
} | ||||||
return expectedName; | ||||||
} | ||||||
} | ||||||
} | ||||||
} |
Uh oh!
There was an error while loading. Please reload this page.