Skip to content

Unparsing FileInfo and DirectoryInfo should add quotes to the path #626

Closed
@kapsiR

Description

@kapsiR

FormatWithQuotesIfString currently honors DateTime, DateTimeOffset and string, but I'm using FileInfo and DirectoryInfo as options as well.

These types should also be surrounded by quotation marks when unparsed.

.NET Fiddle example

Affected code:

private static object FormatWithQuotesIfString(object value)
{
if (value is DateTime || value is DateTimeOffset) return $"\"{value}\"";
Func<string, string> doubQt = v
=> v.Contains("\"") ? v.Replace("\"", "\\\"") : v;
return (value as string)
.ToMaybe()
.MapValueOrDefault(v => v.Contains(' ') || v.Contains("\"")
? "\"".JoinTo(doubQt(v), "\"") : v, value);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions