Skip to content

Refactor code style, enhance security, and fix bugs - #61

Merged
douden merged 4 commits into
mainfrom
claude_merge
Mar 16, 2026
Merged

Refactor code style, enhance security, and fix bugs#61
douden merged 4 commits into
mainfrom
claude_merge

Conversation

@douden

@douden douden commented Mar 16, 2026

Copy link
Copy Markdown
Member

This pull request enhances the sphinx-metadata-figure Sphinx extension with improved metadata handling, more robust license validation, BibTeX integration, and safer HTML rendering. It also updates dependencies and provides better project documentation links. The most important changes are grouped below.

Metadata and License Handling Improvements:

  • Expanded the list of recognized image licenses in VALID_LICENSES to include additional open-source and proprietary licenses, improving compatibility and validation.
  • Improved license validation by reverse-translating license values before comparison, ensuring accurate recognition even after translation for display.

BibTeX and Figure Metadata Integration:

  • Added tracking of generated BibTeX keys to prevent duplicate entries during BibTeX generation, enhancing reliability when processing multiple figures. [1] [2]

HTML Rendering and Safety:

  • Escaped HTML in license attribution display to prevent injection vulnerabilities and ensure safe rendering of metadata in the output.

Extension Initialization and Dependency Management:

  • Updated pyproject.toml to specify minimum versions for dependencies (sphinx>=5.0, myst-nb>=0.17) and added project URLs for homepage, documentation, and bug tracker.
  • Added a guard to prevent double-patching of the HTML translator, making repeated extension setup safe during testing and multi-run scenarios. [1] [2]

These changes collectively improve robustness, usability, and security of the extension.

lkdmc and others added 4 commits March 16, 2026 07:37
…dentation and blank lines (#60)

Code style clean-ups with no behaviour change:

- Module docstring: expanded to reflect all current features (copyright,
  source, multiple placements, page defaults, BibTeX integration, figure
  variants, i18n) instead of only listing the original three fields.

- f-strings without interpolation: two logger.warning() calls used f-string
  prefixes on every string literal despite containing no variables.
  Converted to plain string concatenation.

- Indentation: location= keyword argument in the no-image warning was
  indented one level too shallow (aligned with the string literal instead
  of the opening parenthesis). Fixed to match the rest of the codebase.

- PEP 8 blank lines: added the missing second blank line between
  _parse_bib_entry / _load_user_configured_bib_files and between
  untranslate_license / clear_page_defaults (top-level functions
  require two blank lines between them).

- Typo in comment: "MysST NB" -> "MyST-NB" in setup().

https://claude.ai/code/session_01VHh4HTkZeiMxwZyGMEBypX

Co-authored-by: Claude <noreply@anthropic.com>
… versions (#59)

Two independent improvements:

1. Patch guard: _patch_html_translator() now checks for a sentinel
   attribute (_sphinx_metadata_figure_patched) before applying the
   monkey-patch. Previously, each call to setup() in the same Python
   process (common in multi-run test suites) would re-wrap the already-
   wrapped methods, causing each caption visit to inject license_html
   multiple times.

2. Dependency version constraints: sphinx and myst-nb now have minimum
   version pins (>=5.0 and >=0.17 respectively) to prevent silent
   breakage when installed alongside incompatible older versions.
   Also adds [project.urls] section so PyPI shows Homepage,
   Documentation, and Bug Tracker links.

https://claude.ai/code/session_01VHh4HTkZeiMxwZyGMEBypX

Co-authored-by: Claude <noreply@anthropic.com>
…tion (#58)

Three related security/correctness fixes:

1. XSS: Apply html.escape() to all user-supplied metadata values
   (author, license, copyright, source) when building raw HTML for
   caption placement. Previously, values containing < > & " characters
   could inject arbitrary HTML into the rendered output.

2. VALID_LICENSES mismatch: Add GPL-2.0, LGPL-2.1, LGPL-3.0, AGPL-3.0,
   and BSD-2-Clause to VALID_LICENSES. These licenses had entries in
   LICENSE_URLS (so URL linking was configured) but were absent from
   VALID_LICENSES, causing them to always trigger "unrecognized license"
   warnings regardless of whether strict_check was enabled.

3. License re-validation: In check_all_figures_have_license(), the
   license value stored on a figure node has already been translated
   and formatted for display. Reverse-translate it via untranslate_license()
   before comparing to VALID_LICENSES, otherwise the summaries check
   incorrectly flags every figure as having an unrecognized license.

https://claude.ai/code/session_01VHh4HTkZeiMxwZyGMEBypX

Co-authored-by: Claude <noreply@anthropic.com>
`generated_keys` was referenced before assignment, causing a NameError
at runtime whenever `generate_bib: true` was set in configuration.

Added `generated_keys = set()` before the loop and populated it when
a new entry is appended, so duplicate bib keys within the same scan
are correctly skipped.

https://claude.ai/code/session_01VHh4HTkZeiMxwZyGMEBypX

Co-authored-by: Claude <noreply@anthropic.com>

@douden douden left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Looks okay,

@douden
douden marked this pull request as ready for review March 16, 2026 06:41
@douden
douden merged commit ca9eeb2 into main Mar 16, 2026
3 checks passed
@douden
douden deleted the claude_merge branch March 16, 2026 06:41
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.

2 participants