From b6f50befeca546e41f23c8273e7bb644e3242b2d Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Tue, 13 Jan 2026 11:12:49 +0100 Subject: [PATCH] Restore previous behaviour of ignoring leading or trailing spaces when parsing unit strings (fixes #259) --- quantities/registry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/quantities/registry.py b/quantities/registry.py index 7603965..caecdb1 100644 --- a/quantities/registry.py +++ b/quantities/registry.py @@ -29,7 +29,8 @@ def __init__(self): def __getitem__(self, string): # This approach to avoiding arbitrary evaluation of code is based on https://stackoverflow.com/a/11952618 # by https://stackoverflow.com/users/567292/ecatmur - tree = ast.parse(string, mode="eval") + stripped_string = string.strip() # discard leading or trailing spaces before parsing + tree = ast.parse(stripped_string, mode="eval") valid = all(isinstance(node, self.whitelist) for node in ast.walk(tree)) if valid: try: