Skip to content

[Bug] Various things break when entering double quotes #1557

Closed
@NathanBaulch

Description

@NathanBaulch

I noticed that git commands generated by sourcegit wrap user entered text in double quotes but do not sanitize these strings by escaping double quotes within. This means quite a few things break when entering double quotes, for example git user name in preferences, stash message, etc. And I can only imagine how many issues there would be with double quotes in file names, which is allowed in Linux.

Rather than manually fixing these strings everywhere, I'd like to propose a more thorough solution - changing Command.Args into a StringBuilder and emitting quoted strings with the following extension method:

public static class StringBuilderExtensions
{
    public static StringBuilder AppendQuoted(this StringBuilder sb, string value)
    {
        return sb.Append('"').Append(value.Replace("\"", "\\\"")).Append('"');
    }
}

The Config.SetAsync method for example would look something like this:

Args.Append("config ").Append(scope).Append(' ');
if (!allowEmpty && string.IsNullOrWhiteSpace(value))
    Args.Append("--unset ").Append(key);
else
    Args.Append(key).Append(' ').AppendQuoted(value);

No more interpolated strings and much safer double quote handling. Can I submit a PR for this?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions