-
Notifications
You must be signed in to change notification settings - Fork 119
fix: escape control characters in IfcfgUtil.ValueEscape #894
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
richm
merged 1 commit into
linux-system-roles:main
from
suraj-cmd:fix-valueescape-control-chars
Sep 2, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5657,5 +5657,22 @@ def unstable_fetch(): | |||||||||||||
| self.assertEqual(fetch_mock.call_count, 51) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class TestIfcfgUtilValueEscape(unittest.TestCase): | ||||||||||||||
| def test_plain_value_is_not_quoted(self): | ||||||||||||||
| self.assertEqual(IfcfgUtil.ValueEscape("eth0"), "eth0") | ||||||||||||||
|
|
||||||||||||||
| def test_control_char_escaped_as_octal(self): | ||||||||||||||
| self.assertEqual(IfcfgUtil.ValueEscape("line1\nline2"), "$'line1\\012line2'") | ||||||||||||||
|
|
||||||||||||||
| def test_control_char_with_quote_and_backslash(self): | ||||||||||||||
| self.assertEqual(IfcfgUtil.ValueEscape("a\n'b\\c"), "$'a\\012\\'b\\\\c'") | ||||||||||||||
|
|
||||||||||||||
| def test_double_quoting_path_is_unchanged(self): | ||||||||||||||
| self.assertEqual(IfcfgUtil.ValueEscape('a "b" $c'), '"a \\"b\\" \\$c"') | ||||||||||||||
|
|
||||||||||||||
|
Collaborator
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.
Suggested change
|
||||||||||||||
| def test_octal_escape_is_not_ambiguous_with_following_digit(self): | ||||||||||||||
| self.assertEqual(IfcfgUtil.ValueEscape("\x01" + "1"), "$'\\0011'") | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| if __name__ == "__main__": | ||||||||||||||
| unittest.main() | ||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: linux-system-roles/network
Length of output: 211
🏁 Script executed:
Repository: linux-system-roles/network
Length of output: 8069
🏁 Script executed:
Repository: linux-system-roles/network
Length of output: 17201
🏁 Script executed:
Repository: linux-system-roles/network
Length of output: 223
🌐 Web query:
Python 2.7 Lib/shlex.py shlex.split ANSI-C dollar single quote behavior💡 Result:
In Python 2.7, the shlex.split function and the underlying shlex.shlex class do not support ANSI-C style dollar single quotes (e.g., $'...'). The shlex module is designed to provide lexical analysis for simple shell-like syntaxes [1][2]. When parsing strings, it recognizes standard ASCII single quotes (') and double quotes (") as defined by the shlex.quotes attribute, but it does not have built-in logic to interpret the $ prefix as a special operator for ANSI-C string expansion [1][3]. If you pass a string containing $'...', shlex will treat the dollar sign and the quotes based on its standard configuration: 1. In default POSIX mode (posix=True), the $ sign is treated as a normal character, and the single quotes will be treated as standard quotes that are stripped from the resulting tokens [1][2]. 2. In non-POSIX mode (posix=False), quoting behavior is more restricted (e.g., quotes are not recognized within words), and the $ sign remains a standard character [1][4]. Because shlex.split is intended to mimic basic shell splitting rather than full shell command execution, it does not perform shell-style expansions like ANSI-C quoting, variable substitution, or globbing [1][2]. If you need to handle such syntax, you would need to preprocess the string or use a more robust shell parser [5][6].
Citations:
Keep the writer and parser on the same quoting grammar.
ValueEscapeemits Bash ANSI-C quoting, butIfcfgUtil.ifcfg_parse_lineusesshlex.split, which preserves$and does not decode ANSI-C escapes. Values such as"line1\nline2"therefore fail to round-trip throughcontent_from_dictandcontent_to_dict. Add an end-to-end test and make the parser decode ANSI-C quoting or emit syntax supported by every reader.🤖 Prompt for AI Agents
Source: MCP tools