Skip to content

refactor: add reusable Cleaner API #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025
Merged

refactor: add reusable Cleaner API #90

merged 1 commit into from
Jul 15, 2025

Conversation

messense
Copy link
Owner

No description provided.

@messense messense force-pushed the add-cleaner branch 4 times, most recently from b49f7a8 to 1c2cc07 Compare July 15, 2025 12:56
@messense messense requested a review from Copilot July 15, 2025 13:03
Copy link

@Copilot 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 introduces a reusable Cleaner API that allows users to configure HTML sanitization options once and reuse them for multiple cleaning operations, rather than having to specify all options for each individual clean() call.

  • Adds a new Cleaner struct that holds pre-configured sanitization settings
  • Refactors the existing clean() function to use the new Cleaner internally
  • Introduces self-referencing pattern using the ouroboros crate to manage lifetime dependencies

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/lib.rs Implements the main Cleaner struct with configuration management and refactors the existing clean function
nh3.pyi Adds Python type hints for the new Cleaner class
Cargo.toml Adds ouroboros dependency for self-referencing struct support

});

Ok(cleaned)
let cleaner = Cleaner::py_new(
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

Creating a new Cleaner instance for each call to the clean function defeats the purpose of having a reusable cleaner and impacts performance. Consider using a static default cleaner for cases where all parameters match defaults.

Copilot uses AI. Check for mistakes.

@messense messense merged commit 7c256d6 into main Jul 15, 2025
18 checks passed
@messense messense deleted the add-cleaner branch July 15, 2025 13:30
ColdHeat added a commit to CTFd/CTFd that referenced this pull request Jul 24, 2025
* Update nh3 to 0.3.0
* Use the added Cleaner.clean interface added to nh3 (messense/nh3#90)
* Add tests from the pybluemonday repo
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