Skip to content

Fix sanitizations that result in a macro with arguments#525

Merged
centosinfra-prod-github-app[bot] merged 2 commits intomainfrom
sanitization
Mar 12, 2026
Merged

Fix sanitizations that result in a macro with arguments#525
centosinfra-prod-github-app[bot] merged 2 commits intomainfrom
sanitization

Conversation

@nforro
Copy link
Member

@nforro nforro commented Mar 12, 2026

No description provided.

nforro added 2 commits March 12, 2026 11:32
Signed-off-by: Nikola Forró <nforro@redhat.com>
Signed-off-by: Nikola Forró <nforro@redhat.com>
Assisted-by: Claude Opus 4.6 via Cursor
@gemini-code-assist
Copy link
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 refactors the Lua sanitization logic by encapsulating helper functions within the is_lua_safe method and standardizes the %{sub} macro argument format. These changes aim to improve the consistency and correctness of macro generation, particularly when dealing with arguments, and enhance the robustness of Lua code safety checks.

Highlights

  • Macro Argument Formatting: The format of %{sub} macros has been updated to remove commas between arguments, changing from %{sub MACRO, start, end} to %{sub MACRO start end}.
  • Lua Sanitization Refactoring: The helper functions _strip_lua_comments and _decode_lua_escapes were refactored from global functions into nested functions within Sanitizer.is_lua_safe to encapsulate their logic.
  • Test Case Updates: Existing test cases for %{sub} macro generation and Lua escape decoding were updated to reflect the new macro syntax and to directly test the is_lua_safe method's behavior with various escape sequences.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • specfile/sanitizer.py
    • Removed global _strip_lua_comments and _decode_lua_escapes functions.
    • Re-implemented strip_lua_comments and decode_lua_escapes as nested functions within Sanitizer.is_lua_safe.
    • Modified %{sub} macro generation to use space-separated arguments instead of comma-separated.
    • Updated inline comments and examples to reflect the new %{sub} macro syntax.
  • tests/unit/test_sanitizer.py
    • Updated numerous test assertions to match the new space-separated %{sub} macro format.
    • Refactored test_decode_lua_escapes_out_of_range to directly test Sanitizer.is_lua_safe with various Lua escape sequences, verifying safety implications.
Activity
  • No human activity 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
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

This pull request correctly fixes an issue with macro argument sanitization by removing commas from %{sub} macro arguments, ensuring they are space-separated. The changes are consistently applied across the implementation, documentation, and tests. Additionally, the PR includes a beneficial refactoring that improves encapsulation by nesting helper functions. I have one minor suggestion for a performance improvement related to this refactoring.

Comment on lines +833 to +844
_SIMPLE = {
"a": "\a",
"b": "\b",
"f": "\f",
"n": "\n",
"r": "\r",
"t": "\t",
"v": "\v",
"\\": "\\",
'"': '"',
"'": "'",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This _SIMPLE dictionary is constant and is being recreated on every call to decode_lua_escapes, which is called inside a loop. For a minor performance improvement, you can define it once outside this function, at the is_lua_safe method's scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe later.

@nforro nforro moved this from New to In review in Packit pull requests Mar 12, 2026
@centosinfra-prod-github-app
Copy link
Contributor

@nforro nforro added the mergeit Merge via Zuul label Mar 12, 2026
@centosinfra-prod-github-app
Copy link
Contributor

@centosinfra-prod-github-app centosinfra-prod-github-app bot merged commit 1ac248d into main Mar 12, 2026
46 of 51 checks passed
@github-project-automation github-project-automation bot moved this from In review to Done in Packit pull requests Mar 12, 2026
@nforro nforro deleted the sanitization branch March 12, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mergeit Merge via Zuul

Projects

Development

Successfully merging this pull request may close these issues.

2 participants