Skip to content
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

Fix regex pattern with raw string literals #282

Merged
merged 2 commits into from
Nov 19, 2024
Merged

Conversation

GLWine
Copy link
Contributor

@GLWine GLWine commented Nov 19, 2024

What does this PR do?

  • Updates regular expressions in DiscordAnsiColorText and string_to_alphanumeric to use raw string literals.
  • This ensures correct handling of escape sequences in regular expressions.

Why is this important?

  • The previous regex syntax could have led to misinterpretations of escape sequences, causing errors in string processing and filtering.
  • By switching to raw string literals, we prevent potential bugs and improve the readability and maintainability of the code.

Effects of not applying this change:

  • If left unchanged, the regular expressions could fail to properly process special characters, leading to incorrect results in the application, such as improperly filtered ANSI color codes or failure to correctly remove non-alphanumeric characters.

- Updated the regular expressions for detecting and filtering ANSI color codes.
- Replaced the old string literals with raw string literals (prefix `r`) to avoid potential issues with escape sequences.
- This change ensures the regular expressions are interpreted correctly by Python's `re` module, avoiding potential bugs caused by unescaped characters.
- By applying this fix, we improve the robustness and readability of the regular expressions, ensuring they work reliably in all scenarios.

Effects of not applying the modification:
- Without this change, the regular expressions might not handle escape sequences properly, leading to incorrect matching or errors during pattern compilation.
- This could cause failures in filtering out ANSI color codes, resulting in incorrect or garbled output in the application.
- Updated the regular expression pattern in the `string_to_alphanumeric` function to use a raw string literal (prefix `r`).
- This ensures that backslashes in the pattern are treated correctly, preventing potential issues with escape sequences.
- By making this change, we ensure that the regular expression is interpreted as intended, avoiding any unexpected behavior when cleaning the string.

Effects of not applying the modification:
- Without this fix, the regular expression might not behave correctly due to escape sequences being misinterpreted by Python’s `re` module.
- This could lead to errors in cleaning the string, potentially causing incorrect output or failure to properly remove non-alphanumeric characters.
@aussig aussig merged commit b7e2549 into aussig:develop Nov 19, 2024
2 checks passed
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