fvclaus / vsc-sort-json-array

Visual Studio Code extension that sorts arrays
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

Values get modified #17

Closed vytux-com closed 3 years ago

vytux-com commented 3 years ago

I have the following as a sample JSON to sort

[
    {
        "Name": "a",
        "Base Path": "F:\\Apps\\a"
    },
    {
        "Name": "b",
        "Base Path": "F:\\Apps\\b"
    }
]

After running version 3.0.0 sort it get changed to this

[
    {
        "Name": "a",
        "Base Path": "F:\\\\Apps\\\\a"
    },
    {
        "Name": "b",
        "Base Path": "F:\\\\Apps\\\\b"
    }
]

It appears that the new version is double escaping the values and forgetting to un-escape them after the sort. The same behavior is seen both with built in sorts and Custom sorting scripts.

fvclaus commented 3 years ago

Thanks for reporting this issue. Your observation is correct: The new version is reading the text as is ("\\") without unescaping it, like JSON.parse() would normally do. JSON.stringify() is used to turn the array into text again. It will escape escape the string and turn it into "\\\\". I have to think about how I want to fix this issue. If this is a blocker for you, you can go back to the last version, 2.0.3. I just tested it and it does not contain this issue: https://stackoverflow.com/questions/42626065/vs-code-rollback-extension-install-specific-extension-version

fvclaus commented 3 years ago

This is now part of 3.0.1