Skip to content

refactor: simplify code for unicode extra field and improve error message#724

Merged
Its-Just-Nans merged 3 commits intomasterfrom
single-line-hash
Mar 15, 2026
Merged

refactor: simplify code for unicode extra field and improve error message#724
Its-Just-Nans merged 3 commits intomasterfrom
single-line-hash

Conversation

@Its-Just-Nans
Copy link
Copy Markdown
Member

  • Improve the code of the crc32 calculation (direct hash)
  • Improve the error message of the crc32 calculation
  • Add tests to the crc32 calculation

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the handling of Unicode extra fields by streamlining the CRC32 checksum verification process. The changes aim to make the code more concise, provide clearer error feedback when checksums do not match, and improve the overall robustness through the addition of dedicated unit tests.

Highlights

  • Code Simplification: The CRC32 calculation for Unicode extra fields has been simplified by using a direct hashing function instead of an explicit hasher object.
  • Improved Error Messaging: The error message for CRC32 checksum failures now includes both the expected and actual CRC32 values, formatted in hexadecimal, providing more diagnostic information.
  • Enhanced Test Coverage: New unit tests have been added to validate the CRC32 checksum calculation for Unicode extra fields, covering both correct and incorrect scenarios.
Changelog
  • src/extra_fields/zipinfo_utf8.rs
    • Simplified the CRC32 checksum calculation by replacing the Hasher object with a direct hash function call.
    • Enhanced the error message for CRC32 mismatches to display both the provided and computed checksum values.
    • Added new unit tests to verify the correctness of the Unicode extra field's CRC32 validation logic.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

Summary

This PR simplifies the CRC32 calculation and improves error messages, which aligns well with the PR's stated goals. The code changes are good, but there's a critical defect in the test suite that needs to be fixed before merging.

Critical Issue

  • The test unicode_extra_field_crc32_incorrect has inverted logic - it expects success when it should expect failure, which means it's not actually testing the error case

Changes Reviewed

  • ✅ Simplified CRC32 calculation using direct hash() call
  • ✅ Improved error message with actual vs expected values
  • ❌ Test for incorrect CRC32 has wrong assertion

Please fix the test assertion before merging.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment thread src/extra_fields/zipinfo_utf8.rs Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request simplifies the CRC32 calculation and improves the error message, which are good changes. However, the newly added tests are incorrect. They use an invalid version for the Unicode extra field, an incorrect data size, and in one case, a wrong assertion. I've provided suggestions to fix these tests.

Comment thread src/extra_fields/zipinfo_utf8.rs
Comment thread src/extra_fields/zipinfo_utf8.rs
@Its-Just-Nans Its-Just-Nans changed the title feat: simplify code for unicode extra field and improve error message refactor: simplify code for unicode extra field and improve error message Mar 15, 2026
@Its-Just-Nans Its-Just-Nans added this pull request to the merge queue Mar 15, 2026
Merged via the queue into master with commit 255fcc4 Mar 15, 2026
130 checks passed
@Its-Just-Nans Its-Just-Nans deleted the single-line-hash branch March 15, 2026 17:23
This was referenced Mar 15, 2026
@Its-Just-Nans Its-Just-Nans self-assigned this Mar 19, 2026
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.

1 participant