Hey,
I'd like to contribute two changes upstream but, before I do, I wanted to get your thoughts on if you think you'd accept the changes.
Change #1 - Preserve Whitespace
I'd like to update https://github.com/basgys/goxml2json/blob/master/decoder.go#L136 to not trim white space. I was thinking, to preserve backwards-compatibility I do the following:
- Update
trimNonGraphic to be a function receiver of *Decoder
- Update
Decoder to have a doNotTrimWhitespace property
- Add a
SetDoNotTrimWhitespace *Decoder` function receiver
Change #2 - Customize encoding string sanitization
According to the accepted answer of https://stackoverflow.com/questions/3020094/how-should-i-escape-strings-in-json the only characters we must escape is \, ", and control codes (U+0020 and below). The library currently also escapes <, >, and &. I have an application that needs & to remain unescaped. I was hoping we could allow for users to customize which characters are escaped while retaining backwards-compatibility with the following changes to https://github.com/basgys/goxml2json/blob/master/encoder.go:
- Update Encoder with a new
charactersToEscape property. If not set, default to <>&
- Update https://github.com/basgys/goxml2json/blob/master/encoder.go#L122 to remove
<, >, and & specifically and instead check if the b character is contained within the encoder's charactersToEscape. Would also require updating sanitiseString to be a function receiver of *Encoder.
Thoughts? With the changes everything would remain the same (by default) but still allow for folks to customize things as needed.
Hey,
I'd like to contribute two changes upstream but, before I do, I wanted to get your thoughts on if you think you'd accept the changes.
Change #1 - Preserve Whitespace
I'd like to update https://github.com/basgys/goxml2json/blob/master/decoder.go#L136 to not trim white space. I was thinking, to preserve backwards-compatibility I do the following:
trimNonGraphicto be a function receiver of*DecoderDecoderto have adoNotTrimWhitespacepropertySetDoNotTrimWhitespace*Decoder` function receiverChange #2 - Customize encoding string sanitization
According to the accepted answer of https://stackoverflow.com/questions/3020094/how-should-i-escape-strings-in-json the only characters we must escape is
\,", and control codes (U+0020 and below). The library currently also escapes<,>, and&. I have an application that needs&to remain unescaped. I was hoping we could allow for users to customize which characters are escaped while retaining backwards-compatibility with the following changes to https://github.com/basgys/goxml2json/blob/master/encoder.go:charactersToEscapeproperty. If not set, default to<>&<,>, and&specifically and instead check if thebcharacter is contained within the encoder'scharactersToEscape. Would also require updatingsanitiseStringto be a function receiver of*Encoder.Thoughts? With the changes everything would remain the same (by default) but still allow for folks to customize things as needed.