Browse Source

password file: fix \r\n getting replaced by \n

Fabian Peter Hammerle 3 years ago
parent
commit
9002166fbe
2 changed files with 3 additions and 1 deletions
  1. 2 1
      switchbot_mqtt/__init__.py
  2. 1 0
      tests/test_cli.py

+ 2 - 1
switchbot_mqtt/__init__.py

@@ -209,7 +209,8 @@ def _main() -> None:
     )
     args = argparser.parse_args()
     if args.mqtt_password_path:
-        mqtt_password = args.mqtt_password_path.read_text()
+        # .read_text() replaces \r\n with \n
+        mqtt_password = args.mqtt_password_path.read_bytes().decode()
         if mqtt_password.endswith("\r\n"):
             mqtt_password = mqtt_password[:-2]
         elif mqtt_password.endswith("\n"):

+ 1 - 0
tests/test_cli.py

@@ -79,6 +79,7 @@ def test__main(
         ("secret\n\n", "secret\n"),
         ("secret\r\n", "secret"),
         ("secret\n\r\n", "secret\n"),
+        ("你好\n", "你好"),
     ],
 )
 def test__main_password_file(tmpdir, password_file_content, expected_password):