-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expose Comment in ZipArchive and ZipArchiveEntry #59442
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
08f2a8b
ref: Add public APIs.
carlossanlop 973fc8c
src: Expose the archive and entry comments.
carlossanlop be54e4a
tests: Add update tests for archives and for entries. They cover crea…
carlossanlop 28467ae
Fix encoding detection feedback
carlossanlop 297b9e5
Fix encoding detection feedback
carlossanlop 338b184
Address suggestions
carlossanlop 31a2227
Switch names of archive comment fields.
carlossanlop 78d7e37
Address unicode bit flag sharing problem.
carlossanlop 0a29149
Add more test cases
carlossanlop b93305b
Adjust tests
carlossanlop 7496628
Add newline so comment only applies to one line
carlossanlop a949883
Ensure string byte truncation is aligned to encoding's char size.
carlossanlop 9738c30
Remove empty check for non-nullable string. Also remove unnecessary D…
carlossanlop 5179ea2
Defer calculation of truncated encoding string to getter and to writ…
carlossanlop 0e47de4
Rename test arguments
carlossanlop 18bbcd4
Only use bytes[]
carlossanlop 31602b3
Remove unnecessary bit comment
carlossanlop 0ae8a64
Remove unnecessary length check
carlossanlop e9d5b67
Address feedback
carlossanlop 77b6ee5
Suggestion by adamsitnik: write only if length > 0
carlossanlop 8daedcf
Simplify EntryName code
carlossanlop 1596bb3
Move entryName code to original location
carlossanlop 3444631
In UTF8, use Runes to detect code point length to prevent truncating …
carlossanlop 0749c84
Address suggestions
carlossanlop b08f0ac
Move ZipTestHelper back to its original position because S.IO.Compres…
carlossanlop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Defer calculation of truncated encoding string to getter and to writ…
…ing action when disposing.
- Loading branch information
commit 5179ea2896bf797490500fb117090f8deba72d00
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/libraries/System.IO.Compression/tests/ZipArchive/zip_CreateTests.Comments.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Xunit; | ||
| using System.Text; | ||
|
|
||
| namespace System.IO.Compression.Tests | ||
| { | ||
| public partial class zip_CreateTests : ZipFileTestBase | ||
| { | ||
| [Theory] | ||
| // General purpose bit flag must get the appropriate bit set if a file comment or an entry name is unicode | ||
| [InlineData("ascii", "ascii!!!", "utf-8", "UÄäÖöÕõÜü")] | ||
| [InlineData("utf-8", "UÄäÖöÕõÜü", "ascii", "ascii!!!")] | ||
| [InlineData("ascii", "ascii!!!", "latin1", "LÄäÖöÕõÜü")] | ||
| [InlineData("latin1", "LÄäÖöÕõÜü", "ascii", "ascii!!!")] | ||
| [InlineData("utf-8", "UÄäÖöÕõÜü", "latin1", "LÄäÖöÕõÜü")] | ||
| [InlineData("latin1", "LÄäÖöÕõÜü", "utf-8", "UÄäÖöÕõÜü")] | ||
carlossanlop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static void Create_ZipArchiveEntry_DifferentEncodings_FullName_And_Comment(string en1, string s1, string en2, string s2) | ||
| { | ||
| Encoding e1 = Encoding.GetEncoding(en1); | ||
| Encoding e2 = Encoding.GetEncoding(en2); | ||
| string entryName = e1.GetString(e1.GetBytes(s1)); | ||
| string comment = e2.GetString(e2.GetBytes(s2)); | ||
|
|
||
| var stream = new MemoryStream(); | ||
| var testStream = new WrappedStream(stream, true, true, true, null); | ||
carlossanlop marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Create with no encoding to autoselect it if one of the two strings is unicode | ||
| using (var zip = new ZipArchive(testStream, ZipArchiveMode.Create, leaveOpen: true)) | ||
| { | ||
| ZipArchiveEntry entry = zip.CreateEntry(entryName, CompressionLevel.NoCompression); | ||
| entry.Comment = comment; | ||
|
|
||
| Assert.Equal(entryName, entry.FullName); | ||
| Assert.Equal(comment, entry.Comment); | ||
| } | ||
|
|
||
| // Open with no encoding | ||
| using (var zip = new ZipArchive(testStream, ZipArchiveMode.Read, leaveOpen: false)) | ||
| { | ||
| foreach (var entry in zip.Entries) | ||
| { | ||
| Assert.Equal(entryName, entry.FullName); | ||
| Assert.Equal(comment, entry.Comment); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.