Skip to content

Fix HIGH level code scanning alerts#248

Merged
fabiocaccamo merged 2 commits intomainfrom
copilot/fix-code-scanning-alerts-high-level
Apr 17, 2026
Merged

Fix HIGH level code scanning alerts#248
fabiocaccamo merged 2 commits intomainfrom
copilot/fix-code-scanning-alerts-high-level

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Describe your changes

Fixes the HIGH severity CodeQL code scanning alert py/modification-of-locals in fontbro/font.py.

In set_style_flags(), replaced the pattern:

# Before — CodeQL HIGH alert: py/modification-of-locals
flags = locals()
flags.pop("self")

with an explicit dictionary:

# After — clean, no alert
flags = {
    "regular": regular,
    "bold": bold,
    "italic": italic,
    "underline": underline,
    "outline": outline,
    "shadow": shadow,
    "condensed": condensed,
    "extended": extended,
}

Using locals() to capture function parameters and then mutating the result is flagged by CodeQL as a high-severity anti-pattern (py/modification-of-locals). The explicit dict is semantically equivalent and avoids the warning.

All 175 tests pass and CodeQL Security Scan reports 0 alerts found.

Related issue
?

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

…ct in set_style_flags()

Agent-Logs-Url: https://github.com/fabiocaccamo/python-fontbro/sessions/87a964b2-9231-4d48-b37e-60ea1e5867e3

Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
Copy link
Copy Markdown
Owner

@fabiocaccamo fabiocaccamo left a comment

Choose a reason for hiding this comment

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

Remove font binaries and *.json files changes from this PR.

@fabiocaccamo fabiocaccamo marked this pull request as ready for review April 17, 2026 17:01
Copilot AI review requested due to automatic review settings April 17, 2026 17:01
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

Remove font binaries and *.json files changes from this PR.

Done in 4e58681 — the font binaries and JSON files have been reverted to their original state and are no longer part of this PR.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a HIGH severity CodeQL alert (py/modification-of-locals) by removing mutation of the locals() dictionary in Font.set_style_flags(), and includes a few additional repository updates.

Changes:

  • Replace locals()/pop() usage in set_style_flags() with an explicit flags mapping to avoid the CodeQL alert.
  • Add RobotoMono-Regular.ttf under test fonts for Roboto Mono.
  • Normalize EOF formatting (newline at end) in unicode-scripts.json and unicode-blocks.json.

Reviewed changes

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

File Description
fontbro/font.py Stops mutating locals() by explicitly building the style-flags dict used to set font style bits.
tests/fonts/Roboto_Mono/static/RobotoMono-Regular.ttf Adds a missing/static test font asset for Roboto Mono Regular.
fontbro/data/unicode-scripts.json EOF formatting normalization (adds trailing newline).
fontbro/data/unicode-blocks.json EOF formatting normalization (adds trailing newline).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fontbro/font.py
Comment on lines +2106 to +2115
flags = {
"regular": regular,
"bold": bold,
"italic": italic,
"underline": underline,
"outline": outline,
"shadow": shadow,
"condensed": condensed,
"extended": extended,
}
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

Using an explicit hard-coded flags dict means this method can silently ignore future style-flag parameters if the signature is extended and this dict isn’t updated. To keep behavior in sync with the function parameters while still avoiding the CodeQL py/modification-of-locals alert, consider deriving flags from locals().items() into a new dict (i.e., don’t mutate the locals() result) and filtering out self.

Suggested change
flags = {
"regular": regular,
"bold": bold,
"italic": italic,
"underline": underline,
"outline": outline,
"shadow": shadow,
"condensed": condensed,
"extended": extended,
}
flags = {key: value for key, value in locals().items() if key != "self"}

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.18%. Comparing base (373d611) to head (4e58681).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #248      +/-   ##
==========================================
- Coverage   99.18%   99.18%   -0.01%     
==========================================
  Files           8        8              
  Lines         986      985       -1     
==========================================
- Hits          978      977       -1     
  Misses          8        8              
Flag Coverage Δ
unittests 99.18% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fabiocaccamo fabiocaccamo merged commit 2f54a03 into main Apr 17, 2026
23 checks passed
@fabiocaccamo fabiocaccamo deleted the copilot/fix-code-scanning-alerts-high-level branch April 17, 2026 17:52
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.

3 participants