diff --git a/docs/src/config/ini-config.adoc b/docs/src/config/ini-config.adoc index 9f932eb01cb..6ba256961cb 100644 --- a/docs/src/config/ini-config.adoc +++ b/docs/src/config/ini-config.adoc @@ -59,8 +59,8 @@ Related parts of an INI file are separated into sections. A section name is enclosed in brackets like this: `[THIS_SECTION]`. The order of sections is unimportant. Sections begin at the section name and end at the next section name. -Section identifiers are case senstive and can only contain letters A-Z, a-z, digits 0-9 and underscore (_). -Additionally, section identifiers cannot start with a digit. +Section identifiers are case senstive and can only contain letters A-Z, a-z, digits 0-9, underscore (_) and dash (-). +Additionally, section identifiers cannot start with a digit or a dash. The following sections are used by LinuxCNC: @@ -83,8 +83,8 @@ The following sections are used by LinuxCNC: === Variables(((INI File,Components,Variables))) A variable line is made up of a variable name, an equals sign (`=`), and a value. -A variable identifier is case sensitive and may only consist of letters A-Z, a-z, digits 0-9 and underscore (_). -Additionally, variable identifiers cannot start with a digit. +A variable identifier is case sensitive and may only consist of letters A-Z, a-z, digits 0-9, underscore (_) and dash (-). +Additionally, variable identifiers cannot start with a digit or a dash. White space at the beginning of the line and after the variable identifier, up to the equals sign, is ignored. .Variable Example diff --git a/docs/src/man/man1/inivalue.1.adoc b/docs/src/man/man1/inivalue.1.adoc index 56e4cc25836..82664bb93bb 100644 --- a/docs/src/man/man1/inivalue.1.adoc +++ b/docs/src/man/man1/inivalue.1.adoc @@ -100,7 +100,8 @@ The INI-file format uses the common standard for INI-files with a few additions and exceptions. Section names and variable names may only consist of letters a-z, A-Z, digits -0-9 and underscore (_). The first character in the name cannot be a digit. +0-9, underscore (_) and dash (-). The first character in the name cannot be a +digit or a dash. Comments are specified with the # or ; character and everything following either # or ; is ignored until the end of the line. Embedding a # or ; in a diff --git a/src/emc/ini/inifile.cc b/src/emc/ini/inifile.cc index 2720ce2d70d..7952dd21331 100644 --- a/src/emc/ini/inifile.cc +++ b/src/emc/ini/inifile.cc @@ -48,8 +48,10 @@ static inline void print_msg(const std::string &str) //rcs_print((str + "\n").c_str()); } -// Identifier characters -static const char STR_ID[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789"; +// Identifier characters. The dash is included for compatibility with the +// historic ini parser, which accepted it (e.g. xhc-hb04 pendant layout tags +// like "start-pause" and its [XHC-HB04] cfg section). +static const char STR_ID[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789-"; namespace linuxcnc { // @@ -576,8 +578,8 @@ bool IniFileContent::parseLine(const std::string &line, const std::string &path, path, linenr, sect)); return false; } - if(std::isdigit(sect[0] & 0xff)) { - print_msg(fmt::format("{}:{}: error: Invalid section '{}'. Cannot start with a digit", path, linenr, sect)); + if(std::isdigit(sect[0] & 0xff) || '-' == sect[0]) { + print_msg(fmt::format("{}:{}: error: Invalid section '{}'. Cannot start with a digit or '-'", path, linenr, sect)); return false; } @@ -629,8 +631,8 @@ bool IniFileContent::parseLine(const std::string &line, const std::string &path, path, linenr, tag)); return false; } - if(std::isdigit(tag[0] & 0xff)) { - print_msg(fmt::format("{}:{}: error: Invalid tag '{}'. Tag identifiers cannot start with a digit", path, linenr, tag)); + if(std::isdigit(tag[0] & 0xff) || '-' == tag[0]) { + print_msg(fmt::format("{}:{}: error: Invalid tag '{}'. Tag identifiers cannot start with a digit or '-'", path, linenr, tag)); return false; } diff --git a/tests/inifile/hyphen_identifiers/expected b/tests/inifile/hyphen_identifiers/expected new file mode 100644 index 00000000000..f250ef86645 --- /dev/null +++ b/tests/inifile/hyphen_identifiers/expected @@ -0,0 +1,3 @@ +std +std_start_pause +mdi00 diff --git a/tests/inifile/hyphen_identifiers/hyphenated.ini b/tests/inifile/hyphen_identifiers/hyphenated.ini new file mode 100644 index 00000000000..ea6af5c3c05 --- /dev/null +++ b/tests/inifile/hyphen_identifiers/hyphenated.ini @@ -0,0 +1,8 @@ +# Identifiers containing a dash were accepted by the historic ini parser +# and must keep working (xhc-hb04 pendant layout files use them). +[XHC-HB04] +layout = std + +[buttons] +start-pause = std_start_pause +goto-zero-x = mdi00 diff --git a/tests/inifile/hyphen_identifiers/test.sh b/tests/inifile/hyphen_identifiers/test.sh new file mode 100755 index 00000000000..65fa7111601 --- /dev/null +++ b/tests/inifile/hyphen_identifiers/test.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +inivar -ini hyphenated.ini -sec XHC-HB04 -var layout +inivar -ini hyphenated.ini -sec buttons -var start-pause +inivar -ini hyphenated.ini -sec buttons -var goto-zero-x diff --git a/tests/inifile/inivalue/expected b/tests/inifile/inivalue/expected index 257b8d9c6be..c5bee7ce566 100644 --- a/tests/inifile/inivalue/expected +++ b/tests/inifile/inivalue/expected @@ -15,7 +15,8 @@ xtest.ini:1: error: Invalid section. Missing ']' xtest.ini:1: error: Invalid section. No content between '[' and ']' xtest.ini:1: error: Invalid section. No content between '[' and ']' --- test invalid section, invalid identifier -xtest.ini:1: error: Invalid section '0SECTION'. Cannot start with a digit +xtest.ini:1: error: Invalid section '0SECTION'. Cannot start with a digit or '-' +xtest.ini:1: error: Invalid section '-SECTION'. Cannot start with a digit or '-' xtest.ini:1: error: Invalid section 'xæøåz'. Identifier contains invalid character(s) --- test duplicate section merge warning xtest.ini:2: warning: Section 'SECTION' already exists. Merging... @@ -30,7 +31,8 @@ xtest.ini:2: error: Invalid tag. Missing identifier before '=' --- test invalid variable name missing '=' xtest.ini:2: error: Invalid tag 'VAR x'. Expected '=' after tag identifier --- test invalid variable name identifier -xtest.ini:2: error: Invalid tag '0VAR'. Tag identifiers cannot start with a digit +xtest.ini:2: error: Invalid tag '0VAR'. Tag identifiers cannot start with a digit or '-' +xtest.ini:2: error: Invalid tag '-VAR'. Tag identifiers cannot start with a digit or '-' xtest.ini:2: error: Invalid tag name 'VÅR'. Identifier contains invalid character(s) xtest.ini:2: error: Invalid tag name 'VAR x'. Identifier contains invalid character(s) --- test invalid variable outside section diff --git a/tests/inifile/inivalue/test.sh b/tests/inifile/inivalue/test.sh index f510cc98e11..fd7e7a0addf 100755 --- a/tests/inifile/inivalue/test.sh +++ b/tests/inifile/inivalue/test.sh @@ -53,6 +53,8 @@ tst --var=VAR && t "Invalid section" r "--- test invalid section, invalid identifier" echo "[0SECTION]" > xtest.ini tst --var=VAR && t "Invalid section" +echo "[-SECTION]" > xtest.ini +tst --var=VAR && t "Invalid section" echo "[xæøåz]" > xtest.ini tst --var=VAR && t "Invalid section" @@ -86,6 +88,9 @@ r "--- test invalid variable name identifier" ( echo "[SECTION]" echo "0VAR=val" ) > xtest.ini tst --var=0VAR && t "Invalid variable name" +( echo "[SECTION]" + echo "-VAR=val" ) > xtest.ini +tst --var=-VAR && t "Invalid variable name" ( echo "[SECTION]" echo "VÅR=val" ) > xtest.ini tst --var=VAR && t "Invalid variable name"