Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing INI section names with spaces #16206

Closed
BarrOff opened this issue Dec 1, 2020 · 2 comments · Fixed by #16207
Closed

Error parsing INI section names with spaces #16206

BarrOff opened this issue Dec 1, 2020 · 2 comments · Fixed by #16207

Comments

@BarrOff
Copy link
Contributor

BarrOff commented Dec 1, 2020

I was trying out the example program from the documentation for parsing INI files. If the section name contains spaces, it would parse the INI file incorrectly.

Example INI file

[SectionA]
[Section B]

Current Output

new Section: SectionA
test.ini(2, 10) Error: ']' expected, but found: B
key-value-pair: B:
test.ini(2, 11) Error: invalid token: ]

Expected Output

newSection: SectionA
newSection: Section B

Possible Solution

  • The documentation states, that the configuration syntax is similar to Windows Ini, so maybe this is the expected output?

Additional Information

$ nim -v
Nim Compiler Version 1.4.2
@ringabout
Copy link
Member

ringabout commented Dec 1, 2020

Looks like a bug
Ref:
https://docs.python.org/3.10/library/configparser.html#supported-ini-file-structure

Could you provide your program?

ringabout added a commit to ringabout/Nim that referenced this issue Dec 1, 2020
@ringabout ringabout mentioned this issue Dec 1, 2020
@BarrOff
Copy link
Contributor Author

BarrOff commented Dec 1, 2020

@xflywind here is the program, but this is just a copy from the documentation, see the link in OP

import os, parsecfg, strutils, streams

var f = newFileStream(paramStr(1), fmRead)
if f != nil:
  var p: CfgParser
  open(p, f, paramStr(1))
  while true:
    var e = next(p)
    case e.kind
    of cfgEof: break
    of cfgSectionStart:   ## a ``[section]`` has been parsed
      echo("new section: " & e.section)
    of cfgKeyValuePair:
      echo("key-value-pair: " & e.key & ": " & e.value)
    of cfgOption:
      echo("command: " & e.key & ": " & e.value)
    of cfgError:
      echo(e.msg)
  close(p)
else:
  echo("cannot open: " & paramStr(1))

ringabout added a commit to ringabout/Nim that referenced this issue Dec 3, 2020
@Araq Araq closed this as completed in 849bc36 Dec 3, 2020
@ringabout ringabout reopened this Dec 3, 2020
Araq pushed a commit that referenced this issue Dec 6, 2020
* better docs and tests
* a bit better only clean trailing whitespace
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
* try to fix nim-lang#16206
* merge two parsecfg tests into one
* Revert "fix"

This reverts commit 668bdec.

* Revert "try to fix nim-lang#16206"

This reverts commit c399cc2.
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
* better docs and tests
* a bit better only clean trailing whitespace
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
* try to fix nim-lang#16206
* merge two parsecfg tests into one
* Revert "fix"

This reverts commit 668bdec.

* Revert "try to fix nim-lang#16206"

This reverts commit c399cc2.
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
* better docs and tests
* a bit better only clean trailing whitespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants