-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Several highlighting bugs in INI #2775
Description
Information
- Language: INI
- Plugins: none
Description
Does someone still need INI? :)
Anyway, I’ve made several tests with C (using GetPrivateProfileSectionNames and GetPrivateProfileString from Win32 API), PHP, and Python.
-
Comments. The dollar sign is useless in
/^[ \t]*[;#].*$/m. It is also possible that the dot is harmful, because it matches any character except\n,\r,\u2028, or\u2029(themflag doesn’t change the behavior), whereas\u2028and\u2029can occur inside comments.I confirm that
#and;comment operators are allowed only at the beginning of a line (besides PHP).Example 1.1
[My#Section;Name] my#;key=my#;value
- the section name is
My#Section;Name; - the key is
my#;key; - the value is
my#;value.
- the section name is
-
selectorshould be renamed tonamespace, because sections act like namespaces.Example 2.1
[MySection1] mykey=myvalue1 [MySection2] mykey=myvalue2
Parsers allows to get
mykeyvalues from bothMySection1andMySection2. The second key doesn’t override the first one, so these values aremyvalue1andmyvalue2, respectively. -
Outer brackets should not be included in section names. If multiple square brackets are given, only the first one (from the left) should be considered a paired punctuation mark.
Example 3.1
[foo[bar]The section name is
foo[bar.Example 3.2
[foo]bar]The section name is
foo. -
Section names, keys, values can contain any whitespaces (
\s). Beginning and trailing whitespaces ([ \f\t\v], not[ \t]) on each line should be considered irrelevant.Example 4.1
[ My Section ] my key = my value- the section name is
My␣␣Section, not␣[␣␣␣My␣␣Section␣]; - the key is
my␣␣key; - the value is
my␣␣value, not=␣my␣␣value␣␣␣.
- the section name is
-
Quotes preserve inner spaces.
"and'are allowed, but they are not interchangeable. Parses remove quotes around values.Example 5.1
[ " My Section " ] " my key " = " my value "
- the section name is
"␣My␣␣Section␣␣␣"; - the key is
"␣my␣␣key␣␣␣"; - the value is
␣␣␣my␣␣value␣(without quotes).
- the section name is
-
If multiple equal signs are given, only the first one (from the left) should be considered a key-value separator. All other equal signs should be included in the value.
Example 6.1
mykey==myvalueThe key is
mykey. The value is=myvalue.Example 6.2
foo===bar==baz=qux
The key is
foo. The value is==bar==baz=qux. -
AFAIK, escaping is not implemented in the Win32 API. It is not implemented in Prism too. Should it be implemented?
Notes
-
PHP caveats:
- doesn’t allow
#as a comment operator; - allows inline comments after section names and values;
- doesn’t allow spaces before
[; - doesn’t trim whitespaces around section names (e. g.
[␣My␣␣Section␣␣␣]is interpreted as␣My␣␣Section␣␣␣; same for quoted section names); - doesn’t support quoted keys.
- doesn’t allow
-
Python caveats:
- doesn’t trim whitespaces around section names;
- trims the
\s(not only[ \f\t\v]) whitespaces around keys.
Code snippet
The code being highlighted incorrectly.
# Foo. Here goes U+2028:
. Bar. Baz.
; Foo. Here goes U+2029:
. Bar. Baz.
# The name of the section is My␣␣Section.
# Moreover, it is not a selector, but a namespace.
[ My Section ]
# The name of the section is "␣My␣␣Section␣␣␣".
# Moreover, it is not a selector, but a namespace.
[ " My Section " ]
# Names are My"Section, My"Section"Name, "My"Section", "My"Section"Name".
[My"Section]
[My"Section"Name]
["My"Section"]
["My"Section"Name"]
# Only the leftmost equal sign should be considered a key-value separator.
mykey==myvalue
foo===bar==baz=qux
# Keys can contain any whitespaces.
my key = my value
" my key " = " my value "