Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/src/config/ini-config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/src/man/man1/inivalue.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/emc/ini/inifile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
//
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/inifile/hyphen_identifiers/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
std
std_start_pause
mdi00
8 changes: 8 additions & 0 deletions tests/inifile/hyphen_identifiers/hyphenated.ini
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tests/inifile/hyphen_identifiers/test.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions tests/inifile/inivalue/expected
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/inifile/inivalue/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down
Loading