-
Couldn't load subscription status.
- Fork 5.2k
[release/6.0-staging] Allow setting ZipArchiveEntry general-purpose flag bits #102096
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
Closed
carlossanlop
wants to merge
13
commits into
dotnet:release/6.0-staging
from
carlossanlop:backport/pr-98278-to-release/6.0-staging
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1bfb47a
Add System.IO.Packaging test that checks with reflection that the Zip…
carlossanlop 05dc3be
Use CompressionLevel to set general-purpose bit flags
edwardneal e8ca1a8
Made function verbs consistent
edwardneal 523aff7
Added test to verify read file contents
edwardneal 927a7b6
Corrected failing Packaging test
edwardneal 3ac3a48
Changes following code review
edwardneal 14294e4
Code review changes
edwardneal f09f110
Adapt backported reflection test to .NET 6
carlossanlop aa748a9
Merge branch 'release/6.0-staging' into backport/pr-98278-to-release/…
carlossanlop d797f3a
Minor test fixes
carlossanlop a821c61
Adapt test to 6.0
carlossanlop 5d17840
Adapt test to 6.0
carlossanlop 80fef35
Package authoring changes for System.IO.Packaging and Microsoft.Windo…
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
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
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
59 changes: 59 additions & 0 deletions
59
src/libraries/System.IO.Packaging/tests/ReflectionTests.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,59 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.IO.Compression; | ||
| using System.Reflection; | ||
| using Xunit; | ||
|
|
||
| namespace System.IO.Packaging.Tests; | ||
|
|
||
| public class ReflectionTests | ||
| { | ||
| [Fact] | ||
| public void Verify_GeneralPurposeBitFlag_NotSetTo_Unicode() | ||
| { | ||
| using MemoryStream ms = new(); | ||
|
|
||
| using (ZipPackage package = (ZipPackage)Package.Open(ms, FileMode.Create, FileAccess.Write)) | ||
| { | ||
| Uri uri = PackUriHelper.CreatePartUri(new Uri("document.xml", UriKind.Relative)); | ||
| ZipPackagePart part = (ZipPackagePart)package.CreatePart(uri, Tests.Mime_MediaTypeNames_Text_Xml, CompressionOption.NotCompressed); | ||
| using (Stream partStream = part.GetStream()) | ||
| { | ||
| using StreamWriter sw = new(partStream); | ||
| sw.Write(Tests.s_DocumentXml); | ||
| } | ||
| package.CreateRelationship(part.Uri, TargetMode.Internal, "http://packageRelType", "rId1234"); | ||
| } | ||
|
|
||
| ms.Position = 0; | ||
| using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Read, leaveOpen: false)) | ||
| { | ||
| FieldInfo archiveEncodingFieldInfo = typeof(ZipArchive).GetField("_entryNameEncoding", BindingFlags.Instance | BindingFlags.NonPublic); | ||
| System.Text.Encoding archiveEncoding = (archiveEncodingFieldInfo.GetValue(archive) as System.Text.Encoding) ?? System.Text.Encoding.UTF8; | ||
|
|
||
| foreach (ZipArchiveEntry entry in archive.Entries) | ||
| { | ||
| FieldInfo fieldInfo = typeof(ZipArchiveEntry).GetField("_generalPurposeBitFlag", BindingFlags.Instance | BindingFlags.NonPublic); | ||
| object fieldObject = fieldInfo.GetValue(entry); | ||
| ushort shortField = (ushort)fieldObject; | ||
| Assert.Equal(0, shortField & 0x800); // If it was UTF8, we would set the general purpose bit flag to 0x800 (UnicodeFileNameAndComment) | ||
| CheckCharacters(entry.Name); | ||
| fieldInfo = typeof(ZipArchiveEntry).GetField("_fileComment", BindingFlags.Instance | BindingFlags.NonPublic); | ||
| byte[] commentBytes = (byte[]?)fieldInfo.GetValue(entry) ?? Array.Empty<byte>(); | ||
|
|
||
| CheckCharacters(archiveEncoding.GetString(commentBytes)); | ||
| } | ||
| } | ||
|
|
||
| void CheckCharacters(string value) | ||
| { | ||
| for (int i = 0; i < value.Length; i++) | ||
| { | ||
| char c = value[i]; | ||
| Assert.True(c >= 32 && c <= 126, $"ZipArchiveEntry name character {c} requires UTF8"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
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
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.