terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Settings editor saves settings.json lines with trailing whitespace

Open mrjoel opened this issue 4 years ago • 8 comments

Windows Terminal version (or Windows build number)

1.9.1942.0

Other Software

No response

Steps to reproduce

I have my settings.json tracked in a dotfiles git repo. Recently (now that settings UI is available) I've noticed that the settings.json is save with a trailing space after a name. This appears to be the case when the name is an array or object whose contents continue onto the next line (i.e. the space after the name is always added without considering whether a string value or array/object value will follow.

Expected Behavior

Lines are trimmed when saving

Actual Behavior

Extra spaces are left behind for entries which span multiple lines.

mrjoel avatar Aug 06 '21 16:08 mrjoel

Can you give a specific example? I think I'm having a hard time trying to mentally picture what's wrong here.

zadjii-msft avatar Aug 10 '21 10:08 zadjii-msft

Sure, the specific cases where I see this is happening on my settings.json are listed below, where an extra trailing whitespace character is added.

  • .actions[].command
  • .profiles
  • .profiles.defaults
  • .profiles.list
  • .profiles.schemes

For all of these cases the space is added after the name and colon, but before the value is added, which happens to be on the next line. Instead, I'd expect either to trim each string, or better to use the context to only add the space separator if the next character to be added is not a newline. I haven't taken a look at the code to see how it's handled, but it's curious that .actions is not written with the trailing space, perhaps it gets special handling?

For the case of .actions[].command, what is actually emitted is:

{
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "actions":
    [
        {
            "command": "find", //mrjoel: note that string values on single line are fine, but object values later are not
            "keys": "ctrl+shift+f"
        },
        {
            "command":␣ // mrjoel: '␣' visually represents literal space character here
            {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "keys": "alt+shift+d"
        }
    ],

What is expected is below, note the lack of trailing space (fake depicted as '␣' to be easier to visualize in the diff).

-            "command":␣
+            "command":

mrjoel avatar Aug 11 '21 18:08 mrjoel

these docs for jsoncpp are relevant. IIRC the flag was enableYAMLCompatibility. I could have swore we had this, even some time after #2515

zadjii-msft avatar Feb 17 '22 16:02 zadjii-msft

these docs for jsoncpp are relevant. IIRC the flag was enableYAMLCompatibility. I could have swore we had this, even some time after #2515

@zadjii-msft Hello. Does it suggest that it's an upstream issue? This issue still exists in Windows Terminal Version: 1.19.10573.0. Renaming settings.json and let the WT recreate a default json file have trailing whitespaces too.

networkhermit avatar Mar 23 '24 02:03 networkhermit

I'm not sure! Someone would have to dig into the codebase and make sure we're setting that whenever we're saving the settings. If we are, then yea, I'd bet it's an upstream issue.

zadjii-msft avatar Apr 01 '24 11:04 zadjii-msft

these docs for jsoncpp are relevant. IIRC the flag was enableYAMLCompatibility. I could have swore we had this, even some time after #2515

@zadjii-msft Hello. Does it suggest that it's an upstream issue? This issue still exists in Windows Terminal Version: 1.19.10573.0. Renaming settings.json and let the WT recreate a default json file have trailing whitespaces too.

Looks like a known upstream issue at jsoncpp https://github.com/open-source-parsers/jsoncpp/pull/1154

fallenwood avatar Jun 03 '24 07:06 fallenwood

Hi, I'd like to work on this issue. Could you please assign it to me?

minigithubo avatar Sep 13 '25 11:09 minigithubo

I'd like tho work on this issue , can you please assign me

Retr0-XD avatar Nov 09 '25 16:11 Retr0-XD