Wrap a value that is itself quoted when SetQuotes is on - #101
Merged
Merged
Conversation
The loader strips an outer quote pair from any value that begins and ends with a quote, but the writer only wraps values with leading or trailing whitespace, so such a value lost its quotes on every save/load cycle. The loader already reads the doubled form correctly.
Owner
|
Best way to submit fixes is to have a testcase that shows the failure with the master implementation and is fixed by your patch. |
Owner
|
I'll add it, just for future reference. Thanks for your submission. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
SetQuotes(true), a value that itself begins and ends with a quote loses that pair on everysave/load cycle.
The loader strips an outer pair from any value whose first and last characters are quotes
(
SimpleIni.h:1762):but the writer only wraps when the value has leading or trailing whitespace
(
IsSingleLineQuotedValue,SimpleIni.h:1833, gating the emit atSimpleIni.h:2652). The stripcondition is wider than the wrap condition, so anything in the gap round-trips lossily.
The loader already accepts the form the writer needs to produce
Run against the unmodified header:
So this is not a request for escape support — I know
SetQuotesis deliberately simple quoting,and the reader's own comment says escapes are not supported. It is that the writer does not emit
what its own reader already parses.
Change
Five lines in
IsSingleLineQuotedValue: also wrap when the value begins and ends with a quote.The length check mirrors the loader's
pTrail > a_pVal, so a lone"— which the loader does notstrip — is not wrapped either.
All four cases above then round-trip.
Output change, stated plainly
A value whose data begins and ends with a quote now serializes as
""foo""rather than"foo".That matters to anyone with
SetQuotes(true)who stores such a value and feeds the file to adifferent INI parser. With
SetQuotes(false)the output is byte-identical, and replaying thetests/ts-quotes.cppcorpus through both builds produces byte-identical files, since no value in itbegins and ends with a quote after parsing.
The full gtest suite passes both ways — 255 tests from 25 suites, before and after. (Built by
hand:
cmakewas not available here, so I used theTEST_SOURCESlist fromtests/CMakeLists.txtwith
-Wl,--wrap=malloc, and checked the round trips separately under-fsanitize=address,undefined, which is clean — this is data loss, not memory corruption.)Disclosure: prepared with AI assistance; I verified the round trips, the unmodified-loader
behaviour and both suite runs myself.