-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unparsing FileInfo and DirectoryInfo should add quotes to the path #626
Comments
To support any object that may be string with spaces, i think private static object FormatWithQuotesIfString(object value)
{
// if (value is DateTime || value is DateTimeOffset || value is FileInfo || value is DirectoryInfo) return $"\"{value}\"";
var s = value.ToString();
if (!string.IsNullOrEmpty(s) && !s.Contains("\"") && s.Contains(" "))
return $"\"{s}\"";
Func<string, string> doubQt = v
=> v.Contains("\"") ? v.Replace("\"", "\\\"") : v;
return s.ToMaybe()
.MapValueOrDefault(v => v.Contains(' ') || v.Contains("\"")
? "\"".JoinTo(doubQt(v), "\"") : v, value);
} your test cases are passed using this func. If you agree, you can modify PR and replace this code. |
@moh-hassan Thanks! I changed the PR accordingly. |
@kapsiR |
@moh-hassan Yeah, I'm aware of that and that's the reason why I mentioned it, because we are just looking for a whitespace. [EDIT] |
Sure 😄 |
FormatWithQuotesIfString
currently honorsDateTime
,DateTimeOffset
andstring
, but I'm usingFileInfo
andDirectoryInfo
as options as well.These types should also be surrounded by quotation marks when unparsed.
.NET Fiddle example
Affected code:
commandline/src/CommandLine/UnParserExtensions.cs
Lines 205 to 215 in 24e2be2
The text was updated successfully, but these errors were encountered: