R35007 / sort-json-vscode-extension

Simple JSON Object and Array sort
MIT License
14 stars 2 forks source link

Sorting is evaluating strings with \u0000 Unicode-escaped sequences #4

Closed ZStoner closed 1 year ago

ZStoner commented 1 year ago

I tried to do a sort on some JSON that contains strings with Unicode-escaped sequences. Note: The Unicode-escaped strings weren't part of any "Keys" used for the sort criteria.

Issues:

Sample JSON (before Sort):

{
  "&AElig": { "codepoints": [198], "characters": "\u00C6" },
  "Æ": { "codepoints": [198], "characters": "\u00C6" },
  "↓": { "codepoints": [8595], "characters": "\u2193" },
  "⤓": { "codepoints": [10515], "characters": "\u2913" },
  "⊤": { "codepoints": [8868], "characters": "\u22A4" },
  "↧": { "codepoints": [8615], "characters": "\u21A7" },
  "⇓": { "codepoints": [8659], "characters": "\u21D3" }
}

Resulting JSON (after Sort Ascending):

{
  "&AElig": {
    "codepoints": [
      198
    ],
    "characters": "Æ"
  },
  "Æ": {
    "codepoints": [
      198
    ],
    "characters": "Æ"
  },
  "↓": {
    "codepoints": [
      8595
    ],
    "characters": "↓"
  },
  "⇓": {
    "codepoints": [
      8659
    ],
    "characters": "⇓"
  },
  "⤓": {
    "codepoints": [
      10515
    ],
    "characters": "⤓"
  },
  "⊤": {
    "codepoints": [
      8868
    ],
    "characters": "⊤"
  },
  "↧": {
    "codepoints": [
      8615
    ],
    "characters": "↧"
  }
}
R35007 commented 1 year ago

@ZStoner,

Thanks for pointing out this issue. I will try to resolve it in release and will update you :)

R35007 commented 1 year ago

Hi @ZStoner ,

Since the selected text to sort is converted to JavaScript object all the Unicode will be converted to it's character by default. To overcome this, I have given a fix which may not work for all the Unicode's.

I have added a new vscode sort setting sort-json.settings.preserveUnicodeString. This helps to preserve the Unicode string. Please use this with caution.

Please update the Sort JSON to version 15 Closing this ticket.

Thanks, Siva