Skip to content

Commit 6673e05

Browse files
committed
lib: add fromHexString tests for distressing behaviour
This was cherry‐picked from <#266705> and merged as part of <#318712>, 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.
1 parent a2b5353 commit 6673e05

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

lib/tests/misc.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,30 @@ runTests {
390390
expected = 15;
391391
};
392392

393+
# FIXME: This might be bad and should potentially be deprecated.
394+
testFromHexStringQuestionableMixedCase = {
395+
expr = fromHexString "eEeEe";
396+
expected = 978670;
397+
};
398+
399+
# FIXME: This is probably bad and should potentially be deprecated.
400+
testFromHexStringQuestionableUnderscore = {
401+
expr = fromHexString "F_f";
402+
expected = 255;
403+
};
404+
405+
# FIXME: This is definitely bad and should be deprecated.
406+
testFromHexStringBadComment = {
407+
expr = fromHexString "0 # oops";
408+
expected = 0;
409+
};
410+
411+
# FIXME: Oh my god.
412+
testFromHexStringAwfulInjection = {
413+
expr = fromHexString "1\nwhoops = {}";
414+
expected = 1;
415+
};
416+
393417
testToBaseDigits = {
394418
expr = toBaseDigits 2 6;
395419
expected = [

0 commit comments

Comments
 (0)