fix(function): fix strip_formatting function regex by pawbtism · Pull Request #874 · allthingslinux/tux

Reviewer's Guide

This PR refines the strip_formatting function by updating the regex patterns used for triple and single backtick code blocks to capture and retain inner content instead of removing it entirely, ensuring strings with code block ticks are processed correctly by is_harmful functions.

Sequence Diagram: Impact of strip_formatting Fix on is_harmful Input

sequenceDiagram
    participant C as Caller
    participant SF as strip_formatting
    participant IH as is_harmful

    C->>SF: strip_formatting("Text with ```code_block``` and `inline_code`")
    activate SF
    Note right of SF: Regex updated to preserve content within ```...``` and `...`
    SF-->>C: "Text with code_block and inline_code"
    deactivate SF

    C->>IH: is_harmful("Text with code_block and inline_code")
    activate IH
    Note right of IH: Receives full content, including text previously stripped from code blocks
    IH-->>C: AssessmentResult
    deactivate IH
Loading

File-Level Changes

Change Details Files
Updated regex for triple backtick code blocks to preserve inner content
  • Changed pattern from [\s\S]*? to (.*?)
  • Replaced full removal with capturing group replacement
tux/utils/functions.py
Updated regex for single backtick code blocks to preserve inner content
  • Changed pattern from [^]+to([^]*)
  • Replaced full removal with capturing group replacement
tux/utils/functions.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help