This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 4fdd9eb7792dc8c8c5913101e83d15f88e178a84 Author: Bryan Call <[email protected]> AuthorDate: Wed Jan 7 15:57:33 2026 -0800 Fix convert2yaml.py to handle files without trailing newline (#12784) The script was using value[:-1] to strip the trailing newline, which incorrectly truncates the last character if the file doesn't end with a newline. Changed to value.rstrip('\n') which properly handles both cases. Added test case for config files without trailing newlines. (cherry picked from commit dea3657c624f58a495a7089ee2088a5b9cb29f42) --- tests/gold_tests/records/gold/no_newline.yaml | 3 +++ tests/gold_tests/records/legacy_config/no_newline.config | 1 + tests/gold_tests/records/records_config_to_yaml.test.py | 9 +++++++++ tools/records/convert2yaml.py | 4 ++-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/gold_tests/records/gold/no_newline.yaml b/tests/gold_tests/records/gold/no_newline.yaml new file mode 100644 index 0000000000..82f26fe64f --- /dev/null +++ b/tests/gold_tests/records/gold/no_newline.yaml @@ -0,0 +1,3 @@ +records: + http: + negative_caching_enabled: 0 diff --git a/tests/gold_tests/records/legacy_config/no_newline.config b/tests/gold_tests/records/legacy_config/no_newline.config new file mode 100644 index 0000000000..ace091af5e --- /dev/null +++ b/tests/gold_tests/records/legacy_config/no_newline.config @@ -0,0 +1 @@ +CONFIG proxy.config.http.negative_caching_enabled INT 0 \ No newline at end of file diff --git a/tests/gold_tests/records/records_config_to_yaml.test.py b/tests/gold_tests/records/records_config_to_yaml.test.py index 5996422958..49836a9d75 100644 --- a/tests/gold_tests/records/records_config_to_yaml.test.py +++ b/tests/gold_tests/records/records_config_to_yaml.test.py @@ -56,3 +56,12 @@ tr.Processes.Default.Command = f'python3 convert2yaml.py -f override_map.config tr.Processes.Default.Streams.stdout += Testers.ContainsExpression( "We cannot continue with 'proxy.config.ssl.client.verify.server' at line '3' as an existing YAML map will be overridden.", "Error should be present") + +file_suffix = file_suffix + 1 + +tr = Test.AddTestRun("Test config file without trailing newline") +tr.Setup.Copy(os.path.join(Test.Variables.RepoDir, "tools/records/convert2yaml.py")) +tr.Setup.Copy('legacy_config/no_newline.config') +tr.Processes.Default.Command = f'python3 convert2yaml.py -f no_newline.config --output generated{file_suffix}.yaml --yaml --mute' +f = tr.Disk.File(f"generated{file_suffix}.yaml") +f.Content = "gold/no_newline.yaml" diff --git a/tools/records/convert2yaml.py b/tools/records/convert2yaml.py index 0643715c08..9708f958d9 100755 --- a/tools/records/convert2yaml.py +++ b/tools/records/convert2yaml.py @@ -270,8 +270,8 @@ def handle_file_input(args): elif args.node and name.startswith("proxy.node."): name = name[len("proxy."):] - # Build the object - add_object(config, name, value[:-1], type, track_info) + # Build the object (use rstrip to handle files without trailing newline) + add_object(config, name, value.rstrip('\n'), type, track_info) idx = idx + 1 ts = {}
