commons-configuration
commons-configuration copied to clipboard
CONFIGURATION-822: Fix ambiguity on the section determining
This PR contains small code changes in org.apache.commons.configuration2.INIConfiguration
, which will treat inline comments on section declaration line consistently.
Which INI specification are you implementing? AFIK a semicolon for a comment is only legal at the start of a line (https://en.m.wikipedia.org/wiki/INI_file)
Which INI specification are you implementing? AFIK a semicolon for a comment is only legal at the start of a line (https://en.m.wikipedia.org/wiki/INI_file)
FWIW, I think I saw an INI file at $work this week with comments like that. And from that Wiki page:
Which INI specification are you implementing? AFIK a semicolon for a comment is only legal at the start of a line (https://en.m.wikipedia.org/wiki/INI_file)
Honestly, none particular. But @kinow has, IMHO, correctly pointed out, that some implementations allow inline comments.
What should I do in case I have to process INI file with inline comments? Should I choose an implementation, which allows inline comments? Or should I reinvent the wheel and implement my own solution?
And is it really correct behavior to refuse section determining, just because it contains inline comment? But only in case this comment doesn't end with closing square bracket, otherwise the section is determined, however with obviously wrong section name.
I fully understand your concerns, that my proposal could violate backwards compatibility.
How about following solution?
private boolean inLineCommentsAllowed = false;
public INIConfiguration(boolean inLineCommentsAllowed) {
this.inLineCommentsAllowed = inLineCommentsAllowed;
}
public INIConfiguration() {
}
...
Field will be initialized only on instantiation. No setter will be available.
With field set to false
will INI file parsing proceed backwards compatible.
It seems, that inline comments are already allowed, however, currently only on value lines.
Tested with e.g.: TestINIConfiguration#testValueWithComment
Codecov Report
Merging #229 (776d79b) into master (0e3ce1c) will increase coverage by
0.00%
. The diff coverage is85.71%
.
@@ Coverage Diff @@
## master #229 +/- ##
=========================================
Coverage 89.02% 89.03%
- Complexity 3529 3535 +6
=========================================
Files 183 183
Lines 9642 9648 +6
Branches 1196 1197 +1
=========================================
+ Hits 8584 8590 +6
Misses 777 777
Partials 281 281
Impacted Files | Coverage Δ | |
---|---|---|
...pache/commons/configuration2/INIConfiguration.java | 96.47% <85.71%> (+0.09%) |
:arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
I might update the constructor after a merge to be private and use a builder to avoid the proliferation of constructors...
I might update the constructor after a merge to be private and use a builder to avoid the proliferation of constructors...
Thank you for PR accepting. Builder usage makes sense.