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: Remove sneaky unicode characters that break a regex and console outputs on Windows #6987

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

gukoff
Copy link

@gukoff gukoff commented Jan 31, 2025

User description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

There were 2 almost unnoticeable Unicode characters that caused 2 separate problems:

  1. Regex for ANSI escaping contained the wrong dash, making the regex incorrect.

  2. Message about the file parsing errors failed to be displayed when running on a Windows agent on Azure DevOps:

##[error]2025-01-31 08:10:40,467 [MainThread  ] [ERROR]  Exception traceback:
##[error]Traceback (most recent call last):
##[error]  File "checkov\main.py", line 571, in run
##[error]    exit_codes.append(self.print_results(
##[error]                      ^^^^^^^^^^^^^^^^^^^
##[error]  File "checkov\main.py", line 848, in print_results
##[error]    return runner_registry.print_reports(
##[error]           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
##[error]  File "checkov\common\runners\runner_registry.py", line 643, in print_reports
##[error]    self.save_output_to_file(
##[error]  File "checkov\common\runners\runner_registry.py", line 289, in save_output_to_file
##[error]    file_path.write_text(data)
##[error]  File "pathlib.py", line 1048, in write_text
##[error]  File "encodings\cp1252.py", line 19, in encode
##[error]UnicodeEncodeError: 'charmap' codec can't encode character '\u05bf' in position 156311: character maps to <undefined>

Related: #6416

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes

Generated description

Below is a concise technical summary of the changes proposed in this PR:

Removes an invisible Unicode character (Hebrew Point Rafe) from error messages and comments. Updates regular expression for ANSI escape sequence matching. Improves readability of comments in Kubernetes-related files.

TopicDetails
Error Message Fix Removes an invisible Unicode character from error messages to fix display issues on Windows
Modified files (2)
  • checkov/common/output/report.py
  • checkov/common/runners/runner_registry.py
Latest Contributors(2)
UserCommitDate
lirshindalmanfix-terraform_plan-run...December 01, 2024
[email protected]feat-arm-unsupported-m...October 15, 2024
Comment Cleanup Improves readability of comments in Kubernetes-related files and serverless utilities
Modified files (3)
  • checkov/serverless/utils.py
  • checkov/terraform/checks/resource/kubernetes/HostPort.py
  • checkov/kubernetes/checks/resource/k8s/HostPort.py
Latest Contributors(2)
UserCommitDate
omriyoffe-panwfeat-serverless-Server...December 18, 2024
[email protected]...feat-terraform-include...November 07, 2022
This pull request is reviewed by Baz. Join @gukoff and the rest of your team on (Baz).

@gukoff gukoff changed the title fix: Remove a sneaky Hebrew Point Rafe character that breaks console outputs on Windows fix: Remove a sneaky unicode characters that break a regex and a console outputs on Windows Jan 31, 2025
@gukoff gukoff changed the title fix: Remove a sneaky unicode characters that break a regex and a console outputs on Windows fix: Remove sneaky unicode characters that break a regex and console outputs on Windows Jan 31, 2025
@@ -337,7 +337,7 @@ def print_console(

if not is_quiet:
for file in self.parsing_errors:
output_data += colored(f"Error parsing file {file}ֿ\n", "red")
output_data += colored(f"Error parsing file {file}\n", "red")
Copy link
Author

Choose a reason for hiding this comment

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

This line causes problems with outputs, notice a symbol before \n

@@ -488,7 +488,7 @@ def print_reports(
)

# Remove colors from the cli output
ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[09:;<=>?]*[ -/]*[@-~]')
ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-9:;<=>?]*[ -/]*[@-~]')
Copy link
Author

Choose a reason for hiding this comment

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

This line makes a wrong regex, notice a wrong dash

@@ -9,7 +9,7 @@ def __init__(self) -> None:
"""
https://kubernetes.io/docs/concepts/configuration/overview/

Dont specify a hostPort for a Pod unless it is absolutely necessary.
Don't specify a hostPort for a Pod unless it is absolutely necessary.
Copy link
Author

Choose a reason for hiding this comment

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

This line was changed by the script I made to go over this repo to find bad unicode characters.
I left it in the PR just because unicode seems unnecessary here. There's no bug in this line.

@@ -54,7 +54,7 @@ def get_scannable_file_paths(root_folder: str | None = None, excluded_paths: lis
return files_list

for root, d_names, f_names in os.walk(root_folder):
# Don't walk in to "node_modules" directories under the root folder. If for some reason
# Don't walk in to "node_modules" directories under the root folder. If for some reason
Copy link
Author

Choose a reason for hiding this comment

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

This line was changed by the script I made to go over this repo to find bad unicode characters.
I left it in the PR just because unicode seems unnecessary here. There's no bug in this line.

@@ -9,7 +9,7 @@ def __init__(self):
"""
https://kubernetes.io/docs/concepts/configuration/overview/

Dont specify a hostPort for a Pod unless it is absolutely necessary.
Don't specify a hostPort for a Pod unless it is absolutely necessary.
Copy link
Author

Choose a reason for hiding this comment

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

This line was changed by the script I made to go over this repo to find bad unicode characters.
I left it in the PR just because unicode seems unnecessary here. There's no bug in this line.

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