From b591001250842aa1ae470523d45274243926a853 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 14 Aug 2025 20:57:04 +0100 Subject: [PATCH] lib: add `fromHexString` tests for distressing behaviour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was cherry‐picked from and merged as part of , despite there being a blocking review on the former pointing out these kinds of issues. This documents some of the dodgy behaviour. It also can’t handle negative literals. It might be worth considering deprecating and dropping this, by inlining it into `lib.network.ipv6.fromString`, its only in‐tree user. (cherry picked from commit 6673e05ad065b0f2388c94cc3b3445f9f7da780e) --- lib/tests/misc.nix | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 99b335cdb295..8fd02e49cded 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -390,6 +390,30 @@ runTests { expected = 15; }; + # FIXME: This might be bad and should potentially be deprecated. + testFromHexStringQuestionableMixedCase = { + expr = fromHexString "eEeEe"; + expected = 978670; + }; + + # FIXME: This is probably bad and should potentially be deprecated. + testFromHexStringQuestionableUnderscore = { + expr = fromHexString "F_f"; + expected = 255; + }; + + # FIXME: This is definitely bad and should be deprecated. + testFromHexStringBadComment = { + expr = fromHexString "0 # oops"; + expected = 0; + }; + + # FIXME: Oh my god. + testFromHexStringAwfulInjection = { + expr = fromHexString "1\nwhoops = {}"; + expected = 1; + }; + testToBaseDigits = { expr = toBaseDigits 2 6; expected = [