Skip to content

Commit

Permalink
Fix possible NRE
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gubskiy committed Oct 12, 2024
1 parent 16a6793 commit 6b513af
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/X.PagedList.Mvc.Core/AjaxOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ public enum InsertionMode
/// </remarks>
public class HtmlAttribute
{
public string Key { get; set; }
public object Value { get; set; }
public string Key { get; set; } = "";
public object? Value { get; set; }
}
2 changes: 1 addition & 1 deletion src/X.PagedList.Mvc.Core/PagedListRenderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public static PagedListRenderOptions EnableUnobtrusiveAjaxReplacing(PagedListRen
{
foreach (var ajaxOption in ajaxOptions.ToUnobtrusiveHtmlAttributes())
{
aTagBuilder.Attributes.Add(ajaxOption.Key, ajaxOption.Value.ToString());
aTagBuilder.Attributes.Add(ajaxOption.Key, ajaxOption.Value?.ToString() ?? "");
}
}

Expand Down
64 changes: 5 additions & 59 deletions tests/X.PagedList.Tests/TestDbAsyncQueryProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
Expand Down Expand Up @@ -72,7 +73,7 @@ IQueryProvider IQueryable.Provider
}
}

internal class TestDbAsyncEnumerator<T> : IDbAsyncEnumerator<T>
internal class TestDbAsyncEnumerator<T> : IDbAsyncEnumerator<T>, IDisposable
{
private readonly IEnumerator<T> _inner;

Expand All @@ -86,63 +87,8 @@ public void Dispose()
_inner.Dispose();
}

public Task<bool> MoveNextAsync(CancellationToken cancellationToken)
{
return Task.FromResult(_inner.MoveNext());
}

public T Current
{
get { return _inner.Current; }
}

object? IDbAsyncEnumerator.Current
{
get { return Current; }
}
}

internal class AsyncEnumerableQuery<T> : EnumerableQuery<T>, IDbAsyncEnumerable<T>
{
public AsyncEnumerableQuery(IEnumerable<T> enumerable) : base(enumerable)
{
}

public AsyncEnumerableQuery(Expression expression) : base(expression)
{
}
public T Current => _inner.Current;

public IDbAsyncEnumerator<T> GetAsyncEnumerator()
{
return new InMemoryDbAsyncEnumerator<T>(((IEnumerable<T>)this).GetEnumerator());
}

IDbAsyncEnumerator IDbAsyncEnumerable.GetAsyncEnumerator()
{
return GetAsyncEnumerator();
}

private class InMemoryDbAsyncEnumerator<T> : IDbAsyncEnumerator<T>
{
private readonly IEnumerator<T> _enumerator;

public InMemoryDbAsyncEnumerator(IEnumerator<T> enumerator)
{
_enumerator = enumerator;
}

public void Dispose()
{
}

public Task<bool> MoveNextAsync(CancellationToken cancellationToken)
{
return Task.FromResult(_enumerator.MoveNext());
}

public T Current => _enumerator.Current;

object? IDbAsyncEnumerator.Current => Current;
}
object? IDbAsyncEnumerator.Current => Current;
}
}

0 comments on commit 6b513af

Please sign in to comment.