Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Commit 413c64c

Browse files
committed
Changed date parsing and extracted method
1 parent 8926032 commit 413c64c

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/Nancy/Security/Csrf.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ private static CsrfToken GetCookieToken(Request request)
171171
return cookieToken;
172172
}
173173

174-
private static CsrfToken ParseToCsrfToken(string cookieTokenString)
174+
private static void AddTokenValue(Dictionary<string, string> dictionary, string key, string value)
175175
{
176-
var parsed = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
177-
178-
void Add(string key, string value)
176+
if (!string.IsNullOrEmpty(key))
179177
{
180-
if (!string.IsNullOrEmpty(key))
181-
{
182-
parsed.Add(key, value);
183-
}
178+
dictionary.Add(key, value);
184179
}
180+
}
181+
182+
private static CsrfToken ParseToCsrfToken(string cookieTokenString)
183+
{
184+
var parsed = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
185185

186186
var currentKey = string.Empty;
187187
var buffer = new StringBuilder();
@@ -197,7 +197,7 @@ void Add(string key, string value)
197197
buffer.Clear();
198198
break;
199199
case PairDelimiter:
200-
Add(currentKey, buffer.ToString());
200+
AddTokenValue(parsed, currentKey, buffer.ToString());
201201
buffer.Clear();
202202
break;
203203
default:
@@ -206,7 +206,7 @@ void Add(string key, string value)
206206
}
207207
}
208208

209-
Add(currentKey, buffer.ToString());
209+
AddTokenValue(parsed, currentKey, buffer.ToString());
210210

211211
if (parsed.Keys.Count() != 3)
212212
{
@@ -217,7 +217,7 @@ void Add(string key, string value)
217217
{
218218
return new CsrfToken
219219
{
220-
CreatedDate = DateTimeOffset.ParseExact(parsed["CreatedDate"], "o", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal),
220+
CreatedDate = DateTimeOffset.ParseExact(parsed["CreatedDate"], "o", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal),
221221
Hmac = Convert.FromBase64String(parsed["Hmac"]),
222222
RandomBytes = Convert.FromBase64String(parsed["RandomBytes"])
223223
};

0 commit comments

Comments
 (0)