Skip to content

Commit

Permalink
Fix table writer: avoid array indexing errors. Fix auth test: use typ…
Browse files Browse the repository at this point in the history
…ed object instead of dynamic one. (#1778)
  • Loading branch information
kavics authored Aug 25, 2022
1 parent 33cb8b7 commit 1b3f672
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 13 additions & 8 deletions src/OData/Writers/ODataTableWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ protected override async Task WriteServiceDocumentAsync(HttpContext httpContext,
/// <inheritdoc />
protected override async Task WriteSingleContentAsync(HttpContext httpContext, ODataRequest odataRequest, ODataEntity fields)
{
var expansion = this.ODataRequest.Select
.Select(x => x.Split('/'))
.ToDictionary(x=>x[0], x=>x.Skip(1).ToArray());
var expansion = GetExpansion();

using (var writer = new StringWriter())
{
Expand Down Expand Up @@ -92,7 +90,10 @@ protected override async Task WriteSingleContentAsync(HttpContext httpContext, O
writer.Write(" <tr><td>");
writer.Write(item.Key);
writer.Write("</td><td>");
WriteValue(writer, Project(item.Value, expansion[item.Key]));
if (expansion.TryGetValue(item.Key, out var exp))
WriteValue(writer, Project(item.Value, exp));
else
WriteValue(writer, item.Value);
writer.Write("</td></tr>\n");
}
}
Expand Down Expand Up @@ -189,7 +190,11 @@ protected override async Task WriteMultipleContentAsync(HttpContext httpContext,
{
colIndex = colNames.IndexOf(item.Key);
if (colIndex >= 0)
row[colIndex] = Project(item.Value, expansion[colIndex - 1]);
{
row[colIndex] = expansion.TryGetValue(item.Key, out var exp)
? row[colIndex] = Project(item.Value, exp)
: row[colIndex] = item.Value;
}
}
writer.Write(" <tr>\n");

Expand Down Expand Up @@ -242,11 +247,11 @@ private object GetValueInDepth(ODataEntity entity, string[] expansion, int depth
return value;
}

private string[][] GetExpansion()
private IDictionary<string, string[]> GetExpansion()
{
return this.ODataRequest.Select
.Select(x => x.Split('/').Skip(1).ToArray())
.ToArray();
.Select(x => x.Split('/'))
.ToDictionary(x => x[0], x => x.Skip(1).ToArray());
}

/// <inheritdoc />
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/SenseNet.Services.Core.Tests/AuthenticationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public Task Authentication_Validate_Disabled_CSrv()
var user = await IdentityOperations.CreateLocalUser(root, context, userName, userName, userName + "@example.com");

// check if the user can log in
dynamic result = IdentityOperations.ValidateCredentials(root, context, "public\\" + userName, userName);
Assert.AreEqual(user.Id, result.id);
var result = IdentityOperations.ValidateCredentials(root, context, "public\\" + userName, userName);
Assert.AreEqual(user.Id, result.Id);

// ACTION: disable the user
user["Enabled"] = false;
Expand Down

0 comments on commit 1b3f672

Please sign in to comment.