Skip to content

Open to changes to preserving whitespace and sanitizing strings? #34

@harrisonhjones

Description

@harrisonhjones

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:

  1. Update trimNonGraphic to be a function receiver of *Decoder
  2. Update Decoder to have a doNotTrimWhitespace property
  3. 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:

  1. Update Encoder with a new charactersToEscape property. If not set, default to <>&
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions