Skip to content

Several highlighting bugs in INI #2775

@edukisto

Description

@edukisto

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.

  1. 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 (the m flag doesn’t change the behavior), whereas \u2028 and \u2029 can 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.
  2. selector should be renamed to namespace, because sections act like namespaces.

    Example 2.1

    [MySection1]
    mykey=myvalue1
    
    [MySection2]
    mykey=myvalue2

    Parsers allows to get mykey values from both MySection1 and MySection2. The second key doesn’t override the first one, so these values are myvalue1 and myvalue2, respectively.

  3. 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.

  4. 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␣␣␣.
  5. 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).
  6. 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==myvalue

    The key is mykey. The value is =myvalue.

    Example 6.2

    foo===bar==baz=qux

    The key is foo. The value is ==bar==baz=qux.

  7. AFAIK, escaping is not implemented in the Win32 API. It is not implemented in Prism too. Should it be implemented?

Notes

  1. 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.
  2. Python caveats:

    • doesn’t trim whitespaces around section names;
    • trims the \s (not only [ \f\t\v]) whitespaces around keys.

Code snippet

Test page

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 " 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions