zonyitoo / rust-ini

INI file parser in Rust
MIT License
305 stars 79 forks source link

Empty Section on config file #109

Closed dmatos2012 closed 1 year ago

dmatos2012 commented 1 year ago

Hi, This was raised originally in Nushell https://github.com/nushell/nushell/issues/9556,

  1. Create sample ini
    [placeholder]
    aws_access_key_id=AAAAAAAAAAAAAAAAAAAAA
    aws_secret_access_key=BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
    aws_session_token=BBBBBBBBBBBBBBBBBBBBBBBB
    region=us-east-1
    output=json
    [default]
    aws_access_key_id=AAAAAAAAAAAAAAAAAA
    aws_secret_access_key=AAAAAAAAAAAAAAAAAAAAAAA
    aws_session_token=BBBBBBBBBBBBBBBBBBBBBBBB
    region=us-east-1
    output=json
  2. Get sections

    let i = Ini::load_from_file("conf.ini").unwrap();
    for (sec, prop) in i.iter() {
        println!("Section: {:?}", sec);

    Outputs:

    Section: None
    Section: Some("placeholder")
    Section: Some("default")

    Expected behavior:

    Sections placeholder and default but not None section.

    Thanks!

zonyitoo commented 1 year ago

https://github.com/zonyitoo/rust-ini/blob/371dc9ad2b44afa04d16de38db984f04433659fb/src/lib.rs#L714-L726

It was intended, checkout the comment.

dmatos2012 commented 1 year ago

Ah, It is to allow section-less key-value pairs! Thanks for the fast response!