Skip to content

lib: deprecate fromHexString on dodgy inputs#434218

Merged
emilazy merged 1 commit intoNixOS:masterfrom
emilazy:push-wwwsplnotwlx
Aug 17, 2025
Merged

lib: deprecate fromHexString on dodgy inputs#434218
emilazy merged 1 commit intoNixOS:masterfrom
emilazy:push-wwwsplnotwlx

Conversation

@emilazy
Copy link
Member

@emilazy emilazy commented Aug 16, 2025

See #433710.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nix-owners nix-owners bot requested review from hsjobeki and infinisil August 16, 2025 12:28
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 6.topic: lib The Nixpkgs function library labels Aug 16, 2025
@emilazy emilazy force-pushed the push-wwwsplnotwlx branch from ae1bd4f to 3c7d67d Compare August 16, 2025 12:36
@emilazy
Copy link
Member Author

emilazy commented Aug 16, 2025

(Whoops, made the regex slightly too strict… fixed and added a test to catch my mistake. We could also choose to allow longer strings of leading zeroes, but I’d prefer to permit only the minimal format that people are observably using in the wild for now, and worry about all the rest after we have closed off the rest of the input space.)

str:
let
noPrefix = lib.strings.removePrefix "0x" (lib.strings.toLower value);
match = builtins.match "(0x)?([0-7]?[0-9A-Fa-f]{1,15})" str;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe should be case insensitive in the 0x part? idk. we did have a test for it working.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn’t find any examples of people using that in my GitHub search, and it’s inconsistent with the syntax of TOML and C (although Python does allow it). I’d prefer to err on the side of conservatism here so that we can buy ourselves back maximum freedom to determine the input space without (hopefully) breaking any existing users, though I’m not super fussed one way or the other here. We’re already in the territory of breaking the tests/examples out of necessity. Honestly I don’t even like the optional 0x here, but there are users of it in the wild, so we shouldn’t break them without good reason; I think this is the most rigid non‐arbitrary format that covers everything I saw. (Well, possibly we could disallow mixed case in the actual digits too, but I don’t see the point.)

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Aug 16, 2025
@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Aug 17, 2025
@emilazy emilazy merged commit 922b647 into NixOS:master Aug 17, 2025
25 checks passed
@emilazy emilazy deleted the push-wwwsplnotwlx branch August 17, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants