From f6b69cf5e3aca4ab745e666f5485a4a5f628fe77 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 26 Dec 2022 10:49:57 -0600 Subject: [PATCH] Allow settings.toml to end without a newline --- shared-module/os/getenv.c | 2 +- tests/circuitpython/getenv.py | 3 +++ tests/circuitpython/getenv.py.exp | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/shared-module/os/getenv.c b/shared-module/os/getenv.c index d9e75484ec..21a97f3fec 100644 --- a/shared-module/os/getenv.c +++ b/shared-module/os/getenv.c @@ -201,6 +201,7 @@ STATIC os_getenv_err_t read_string_value(file_arg *active_file, vstr_t *buf) { case '#': next_line(active_file); MP_FALLTHROUGH; + case 0: case '\n': return GETENV_OK; default: @@ -257,7 +258,6 @@ STATIC os_getenv_err_t read_bare_value(file_arg *active_file, vstr_t *buf, int f while (true) { switch (character) { case 0: - return GETENV_ERR_UNEXPECTED | character; case '\n': return GETENV_OK; case '#': diff --git a/tests/circuitpython/getenv.py b/tests/circuitpython/getenv.py index ad8fdbfeeb..b63f587730 100644 --- a/tests/circuitpython/getenv.py +++ b/tests/circuitpython/getenv.py @@ -75,5 +75,8 @@ def run_test(key, content): for i in range(13): run_test(f"key{i}", content_good) +# Test value without trailing newline +run_test(f"noeol", "noeol=3") + for content in content_bad: run_test("key", content) diff --git a/tests/circuitpython/getenv.py.exp b/tests/circuitpython/getenv.py.exp index f83143c80b..0dcc8f78d3 100644 --- a/tests/circuitpython/getenv.py.exp +++ b/tests/circuitpython/getenv.py.exp @@ -11,6 +11,7 @@ key9 'hello comment' key10 127 key11 0 key12 None +noeol 3 key Invalid byte '\n' key Invalid byte '"' key invalid syntax for integer with base 10: ''