go-configparser icon indicating copy to clipboard operation
go-configparser copied to clipboard

Fix parsing of values on new lines by enabling empty lines in multiline values by default

Open Copilot opened this issue 5 months ago • 1 comments

This PR fixes an issue where the configparser failed to parse values that are placed on a new line after the key, particularly when there are empty lines between the key and value.

Problem

The library was not correctly handling cases like:

[section]
option3 =
    value3

Where parser.Get("section", "option3") would return an empty string instead of "value3" when there were empty lines between the key and the multiline value.

Root Cause

The parsing logic would terminate multiline value parsing when encountering empty lines, unless the AllowEmptyLines option was explicitly enabled. This behavior was counter-intuitive for users who expected standard configuration file multiline value behavior.

Solution

  • Enable the emptyLines option by default in defaultOptions()
  • Update the existing test case that expected the old behavior to reflect the new, more intuitive behavior
  • Add a comprehensive test case to validate newline value parsing scenarios

Impact

This change makes the library more user-friendly by allowing empty lines in multiline values by default, which aligns with common expectations for configuration file parsing. While this is technically a breaking change in behavior, it makes the library work as users intuitively expect.

All existing tests continue to pass, and the core functionality (interpolation, basic parsing, etc.) remains unchanged.

Fixes #14.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Aug 14 '25 09:08 Copilot