This is an automated email from the ASF dual-hosted git repository. ephraimanierobi pushed a commit to branch v2-2-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit e63f09729b361510254f85fa1791ed54eb519ce2 Author: Davy <kadai0...@gmail.com> AuthorDate: Thu Feb 24 15:40:57 2022 +0800 Correctly handle multiple '=' in LocalFileSystem secrets. (#21694) (cherry picked from commit 919b75ba20083cc83c4e84e35aae8102af2b5871) --- airflow/secrets/local_filesystem.py | 7 +++---- tests/secrets/test_local_filesystem.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/airflow/secrets/local_filesystem.py b/airflow/secrets/local_filesystem.py index d23969f..227a77c 100644 --- a/airflow/secrets/local_filesystem.py +++ b/airflow/secrets/local_filesystem.py @@ -75,8 +75,8 @@ def _parse_env_file(file_path: str) -> Tuple[Dict[str, List[str]], List[FileSynt # Ignore comments continue - var_parts: List[str] = line.split("=", 2) - if len(var_parts) != 2: + key, sep, value = line.partition("=") + if not sep: errors.append( FileSyntaxError( line_no=line_no, @@ -85,8 +85,7 @@ def _parse_env_file(file_path: str) -> Tuple[Dict[str, List[str]], List[FileSynt ) continue - key, value = var_parts - if not key: + if not value: errors.append( FileSyntaxError( line_no=line_no, diff --git a/tests/secrets/test_local_filesystem.py b/tests/secrets/test_local_filesystem.py index 85f0aaa..5993eb3 100644 --- a/tests/secrets/test_local_filesystem.py +++ b/tests/secrets/test_local_filesystem.py @@ -155,6 +155,23 @@ class TestLoadConnection(unittest.TestCase): @parameterized.expand( ( + ( + "CONN_ID=mysql://host_1?param1=val1¶m2=val2", + {"CONN_ID": "mysql://host_1?param1=val1¶m2=val2"}, + ), + ) + ) + def test_parsing_with_params(self, content, expected_connection_uris): + with mock_local_file(content): + connections_by_conn_id = local_filesystem.load_connections_dict("a.env") + connection_uris_by_conn_id = { + conn_id: connection.get_uri() for conn_id, connection in connections_by_conn_id.items() + } + + assert expected_connection_uris == connection_uris_by_conn_id + + @parameterized.expand( + ( ("AA", 'Invalid line format. The line should contain at least one equal sign ("=")'), ("=", "Invalid line format. Key is empty."), )