Whole file
slomkowski/nginx-config-formatter
The author described this change as “Fix error which split line when it contained backslash. Fixes #5”. It counts as a record because the checks below fail on the code as it stood at 4488f2ee6 and pass on f5a26225b, with nothing else changed between the two runs.
Fix saved2017-07-26
Sharing licenceApache-2.0 · LICENSE
Change size+5 −4
What the code was meant to do, written into the code itself as a save note
Fix error which split line when it contained backslash. Fixes #5
The change
| 13 | 13 | ||
| 14 | 14 | __author__ = "Michał Słomkowski" | |
| 15 | 15 | __license__ = "Apache 2.0" | |
| 16 | - | __version__ = "1.0.1" | |
| 16 | + | __version__ = "1.0.2" | |
| 17 | 17 | ||
| 18 | 18 | INDENTATION = ' ' * 4 | |
| 19 | 19 | ||
| ⋯ | |||
| 54 | 54 | flags=re.UNICODE) | |
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | - | def clean_lines(orig_lines): | |
| 57 | + | def clean_lines(orig_lines) -> list: | |
| 58 | 58 | """Strips the lines and splits them if they contain curly brackets.""" | |
| 59 | 59 | cleaned_lines = [] | |
| 60 | 60 | for line in orig_lines: | |
| ⋯ | |||
| 68 | 68 | cleaned_lines.append(strip_variable_template_tags(line)) | |
| 69 | 69 | else: | |
| 70 | 70 | cleaned_lines.extend( | |
| 71 | - | [strip_variable_template_tags(l).strip() for l in re.split(r"([{\\}])", line) if l != ""]) | |
| 71 | + | [strip_variable_template_tags(l).strip() for l in re.split(r"([{}])", line) if l != ""]) | |
| 72 | 72 | ||
| 73 | 73 | return cleaned_lines | |
| 74 | 74 | ||
| ⋯ | |||
| 105 | 105 | ||
| 106 | 106 | def format_config_contents(contents): | |
| 107 | 107 | """Accepts the string containing nginx configuration and returns formatted one. Adds newline at the end.""" | |
| 108 | - | lines = clean_lines(contents.splitlines()) | |
| 108 | + | lines = contents.splitlines() | |
| 109 | + | lines = clean_lines(lines) | |
| 109 | 110 | lines = join_opening_bracket(lines) | |
| 110 | 111 | lines = perform_indentation(lines) | |
| 111 | 112 | ||
The check that tells the two apart
fail→pass·test_nginxfmt.py::TestFormatter::test_backslash
fail→pass·test_nginxfmt.py::TestFormatter::test_clean_lines
Check file test_nginxfmt.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it4488f2ee63fa73a20a3499f145277dec8cb2f0c2
Broken version dated2017-07-20
Modulenginxfmt
Units changedclean_lines, format_config_contents
Fingerprintf6cae73c854eb0d6
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in slomkowski/nginx-config-formatter
- 2016-06-16Fix error with brackets in comments.