Skip to content

Commit

Permalink
Поддержка null'ых значений
Browse files Browse the repository at this point in the history
  • Loading branch information
Zymlex committed Jul 13, 2020
1 parent b8fa063 commit 7bc71e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 12 additions & 13 deletions JsonToNetscape/CookieObj.cs
Expand Up @@ -7,30 +7,29 @@ namespace JsonToNetscape
public class CookieObj
{
public string domain { get; set; }
public double expirationDate { get; set; }
public bool hostOnly { get; set; }
public bool httpOnly { get; set; }
public double? expirationDate { get; set; }
public bool? hostOnly { get; set; }
public bool? httpOnly { get; set; }
public string name { get; set; }
public string path { get; set; }
public string sameSite { get; set; }
public bool secure { get; set; }
public bool session { get; set; }
public bool? secure { get; set; }
public bool? session { get; set; }
public string storeId { get; set; }
public string value { get; set; }
public int id { get; set; }
public int? id { get; set; }

public override string ToString()
{
var expiryStr = (expirationDate >= 0 ? TimeUtils.FromSecondsSinceEpoch(expirationDate) : DateTime.MinValue).ToString(CultureInfo.InvariantCulture).ToUpper();
var expiryStr = expirationDate != null ? (expirationDate >= 0 ? TimeUtils.FromSecondsSinceEpoch((double)expirationDate) : DateTime.MinValue).ToString(CultureInfo.InvariantCulture).ToUpper() : null;

var sameSiteStr = "Unspecified";
if (sameSite.Contains("lax")) sameSiteStr = "Lax";
if (sameSite.Contains("strict")) sameSiteStr = "Strict";
if (sameSite?.Contains("lax") ?? false) sameSiteStr = "Lax";
if (sameSite?.Contains("strict") ?? false) sameSiteStr = "Strict";

return domain + "\t" + (!string.IsNullOrWhiteSpace(domain)).ToString(CultureInfo.InvariantCulture).ToUpper() + "\t" + path + "\t" + secure.ToString(CultureInfo.InvariantCulture).ToUpper() + "\t" +
expiryStr.ToString(CultureInfo.InvariantCulture).ToUpper() +
"\t" + name + "\t" + value + "\t" + httpOnly.ToString(CultureInfo.InvariantCulture).ToUpper() + "\t" +
(expirationDate < 0.01).ToString(CultureInfo.InvariantCulture).ToUpper() + "\t" + sameSiteStr + "\t" + "Medium";
return domain + "\t" + (!string.IsNullOrWhiteSpace(domain)).ToString(CultureInfo.InvariantCulture).ToUpper() + "\t" + path + "\t" + (secure?.ToString(CultureInfo.InvariantCulture).ToUpper() ?? "FALSE") + "\t" +
expiryStr + "\t" + name + "\t" + value + "\t" + (httpOnly?.ToString(CultureInfo.InvariantCulture).ToUpper() ?? "FALSE") + "\t" +
(expirationDate == null || expirationDate < 0.01).ToString(CultureInfo.InvariantCulture).ToUpper() + "\t" + sameSiteStr + "\t" + "Medium";

}

Expand Down
2 changes: 2 additions & 0 deletions JsonToNetscape/Program.cs
Expand Up @@ -8,6 +8,8 @@ namespace JsonToNetscape
{
internal static class Program
{
// "Host\tDomainFlag\tPath\tSecureFlag\tExpiry\tName\tValue\tHttpOnlyFlag\tSessionFlag\r\n ..." for Firefox
// "Host\tDomainFlag\tPath\tSecureFlag\tExpiry\tName\tValue\tHttpOnlyFlag\tSessionFlag\tSameSite\tPriority\r\n ..." for Chrome.</para>
private static void Main(string[] args)
{
if (args.Length == 0)
Expand Down

0 comments on commit 7bc71e5

Please sign in to comment.