-
Notifications
You must be signed in to change notification settings - Fork 54
Escape characters inline #231
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,36 @@ def escape_backslashes(text: str) -> str: | |
| return text.replace("\\", "\\\\") | ||
|
|
||
|
|
||
| def escape_control_characters(text: str) -> str: | ||
| if not text: | ||
| return text | ||
|
|
||
| translation_table = str.maketrans( | ||
| { | ||
| "\x00": "\\x00", # Null | ||
| "\x08": "\\b", # Backspace | ||
| "\x0b": "\\v", # Vertical tab | ||
| "\x0c": "\\f", # Form feed | ||
| "\x1b": "\\x1b", # Escape | ||
| "\x7f": "\\x7f", # Delete | ||
| "\u00a0": "\\u00a0", # Non-breaking space | ||
| "\u200b": "\\u200b", # Zero-width space | ||
| "\u200c": "\\u200c", # Zero-width non-joiner | ||
| "\u200d": "\\u200d", # Zero-width joiner | ||
| "\u200e": "\\u200e", # Left-to-right mark | ||
| "\u200f": "\\u200f", # Right-to-left mark | ||
| "\u202c": "\\u202c", # Pop directional formatting | ||
| "\u202d": "\\u202d", # Left-to-right override | ||
| "\u202e": "\\u202e", # Right-to-left override | ||
| "\u2028": "\\u2028", # Line separator | ||
| "\u2029": "\\u2029", # Paragraph separator | ||
| "\ufeff": "\\ufeff", # Byte order mark | ||
| } | ||
| ) | ||
|
|
||
| return text.translate(translation_table) | ||
|
|
||
|
|
||
| class InlinePythonReporter(Reporter): | ||
| def __init__( | ||
| self, | ||
|
|
@@ -64,10 +94,9 @@ def create_received_file(self, received_path: str, test_source_file: str) -> str | |
|
|
||
| original_received_text = Path(received_path).read_text(encoding="utf-8")[:-1] | ||
| received_text = original_received_text + self.footer | ||
| # Handle preceding whitespace consistently across all lines. | ||
| received_text = handle_preceeding_whitespace(received_text) | ||
| # Escape backslashes to avoid accidental escape sequences in the docstring. | ||
| received_text = escape_backslashes(received_text) | ||
| received_text = escape_control_characters(received_text) | ||
|
Comment on lines
98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Consider the ordering of backslash vs control-character escaping to keep behavior consistent. Currently, |
||
| method_name = StackFrameNamer.get_test_frame().function | ||
| if detect_trailing_whitespace(original_received_text): | ||
| trailing_comment = " # Warning: Editors may remove trailing spaces, causing this test to fail" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: The retry step always runs rather than conditionally on failure.
As written, this will always run
mise installtwice—once viajdx/mise-actionand once in this step—rather than only retrying on failure. If you want an actual retry, consider gating this on a previous step’s failure withif: ${{ failure() }}or using a dedicated retry wrapper, so you avoid extra work when the initial install succeeds.