From fe48be2ab5fd81ae4d751bb35776ff13674e5c6c Mon Sep 17 00:00:00 2001 From: Alexander Braverman Masis Date: Mon, 25 Nov 2024 14:59:31 -0500 Subject: [PATCH] formats.libconfig: add support for dashes --- pkgs/pkgs-lib/formats/libconfig/src/src/main.rs | 2 +- pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix | 3 +++ .../pkgs-lib/formats/libconfig/test/comprehensive/expected.txt | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/pkgs-lib/formats/libconfig/src/src/main.rs b/pkgs/pkgs-lib/formats/libconfig/src/src/main.rs index 4da45f647d46..941dbcaa5a78 100644 --- a/pkgs/pkgs-lib/formats/libconfig/src/src/main.rs +++ b/pkgs/pkgs-lib/formats/libconfig/src/src/main.rs @@ -24,7 +24,7 @@ fn validate_setting_name(key: &str) -> bool { (first_char.is_alphabetic() || first_char == '*') && key[1..] .chars() - .all(|c| c.is_alphanumeric() || c == '_' || c == '*') + .all(|c| c.is_alphanumeric() || c == '_' || c == '*' || c == '-') } const SPECIAL_TYPES: [&str; 5] = ["octal", "hex", "float", "list", "array"]; diff --git a/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix b/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix index 7b0df23ee663..e14fcce2f099 100644 --- a/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix +++ b/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/default.nix @@ -14,6 +14,9 @@ let simple_top_level_attr = "1.0"; nested.attrset.has.a.integer.value = 100; some_floaty = 29.95; + ## dashes in key names + top-level-dash = "pass"; + nested.level-dash = "pass"; ## Same syntax here on these two, but they should get serialized differently: # > A list may have zero or more elements, each of which can be a scalar value, an array, a group, or another list. list1d = libconfig.lib.mkList [ 1 "mixed!" 5 2 ]; diff --git a/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/expected.txt b/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/expected.txt index ef6e09f8111a..0bdf80f8a749 100644 --- a/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/expected.txt +++ b/pkgs/pkgs-lib/formats/libconfig/test/comprehensive/expected.txt @@ -1,6 +1,6 @@ array1d=[1, 5, 2];array2d=([1, 2], [2, 1]);list1d=(1, "mixed!", 5, 2);list2d=(1, (1, 1.2, "foo"), ("bar", 1.2, 1));nasty_string="\"@ \\ ^*bf -0\";'''$";nested={attrset={has={a={integer={value=100;};};};};};simple_top_level_attr="1.0";some_floaty=29.95;weirderTypes={ +0\";'''$";nested={attrset={has={a={integer={value=100;};};};};level-dash="pass";};simple_top_level_attr="1.0";some_floaty=29.95;top-level-dash="pass";weirderTypes={ @include "@include_file@" array_of_ints=[0732, 0xa3, 1234];bigint=9223372036854775807;float=0.0012;hex=0x1fc3;list_of_weird_types=(3.141592654, 9223372036854775807, 0x1fc3, 027, 1.2e-32, 1.0);octal=027;pi=3.141592654;};