Skip to content

Preserve percent-encoding in OPC part references - #1070

Merged
dtivel merged 2 commits into
mainfrom
dtivel-preserve-opc-uri-escaping
Sep 14, 2026
Merged

dtivel merged 2 commits into
mainfrom
dtivel-preserve-opc-uri-escaping

Conversation

@dtivel

@dtivel dtivel commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1071.

Summary

Preserve existing percent-encoding when resolving and serializing OPC part URIs.

This fixes conforming packages whose physical ZIP entry names are already encoded—for example, ab%23c.txt. Signature references now retain %23 exactly once instead of emitting either # or %2523.

The change:

  • preserves escaped part names during ZIP-entry lookup;
  • preserves escaping in signature Reference/@URI values and relationship targets;
  • keeps escaped-path comparisons consistent when excluding existing signature parts;
  • covers encoded #, ?, %, UTF-8 names, nested paths, and ordinary names;
  • dynamically constructs test packages instead of adding binary fixtures; and
  • independently verifies generated signatures with PackageDigitalSignatureManager.VerifySignatures().

Scope

This PR handles conforming OPC part names that are already percent-encoded in the physical ZIP package.

It does not make raw URI delimiters in ZIP entry names valid. #1069 separately rejects raw # and ? characters before URI parsing and carries the fix for #998.

This supersedes the escaping approach in #1063, which can double-encode an already-conforming name such as ab%23c.txt as ab%2523c.txt.

Testing

All discovered solution tests pass: 780 passed, 1 skipped, 0 failed.

This change adds 3 test methods and expands existing URI-helper theories to cover:

  • encoded #, ?, and % characters;
  • nested and ordinary part names;
  • percent-encoded UTF-8 names;
  • exact signature Reference/@URI values;
  • relationship target serialization;
  • prevention of decoded and double-encoded references; and
  • independent verification with PackageDigitalSignatureManager.VerifySignatures().

All test packages are constructed dynamically; no binary .vsix fixtures are added.

Keep escaped OPC part names intact when resolving ZIP entries and serializing signature or relationship URIs. Add generated-package interoperability coverage with System.IO.Packaging.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@dtivel
dtivel requested a review from a team as a code owner September 13, 2026 20:30
@dtivel
dtivel requested a balanced review from Copilot September 13, 2026 20:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation consistently preserves encoded paths and includes focused end-to-end verification coverage.

Review tier: Balanced
Findings: None

What changed in this PR

Preserves conforming percent-encoded OPC part names throughout ZIP lookup, signature generation, and relationship serialization.

Changes:

  • Uses escaped URI representations for package paths, references, and comparisons.
  • Adds coverage for reserved characters, UTF-8 names, nested paths, and signature verification.
  • Adds Windows Desktop runtime support for independent verification tests.
File Description
src/​Sign.Core/​Tools/​VsixSignTool/​UriHelpers.cs Preserves URI escaping during path conversion.
src/​Sign.Core/​Tools/​VsixSignTool/​VSIXSignatureBuilderPreset.cs Compares signature paths in escaped form.
test/​Sign.Core.Test/​Tools/​VSIXSignTool/​UriHelpersTests.cs Expands URI and relationship serialization coverage.
test/​Sign.Core.Test/​Tools/​VSIXSignTool/​OpcPackageSigningTests.cs Tests encoded entries and independent signature verification.
test/​Sign.Core.Test/​Sign.Core.Test.csproj References WindowsBase through WPF.
global.json Adds the Windows Desktop runtime dependency.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dtivel
dtivel requested a review from kartheekp-ms September 13, 2026 22:40
pjcollins
pjcollins previously approved these changes Sep 14, 2026
Preserve encoded OPC entry names while retaining raw and decoded URI delimiter validation before part creation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ff04667a-44b8-4113-b777-a18549f5819e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve percent-encoding for conforming OPC part names during signing

3 participants