From 6b513afe9135da911d92e0ad8bf3e7f3ce3d5907 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 12 Oct 2024 23:35:52 +0300 Subject: [PATCH] Fix possible NRE --- src/X.PagedList.Mvc.Core/AjaxOptions.cs | 4 +- .../PagedListRenderOptions.cs | 2 +- .../TestDbAsyncQueryProvider.cs | 64 ++----------------- 3 files changed, 8 insertions(+), 62 deletions(-) diff --git a/src/X.PagedList.Mvc.Core/AjaxOptions.cs b/src/X.PagedList.Mvc.Core/AjaxOptions.cs index 2ddbaa19..ce42efd0 100644 --- a/src/X.PagedList.Mvc.Core/AjaxOptions.cs +++ b/src/X.PagedList.Mvc.Core/AjaxOptions.cs @@ -97,6 +97,6 @@ public enum InsertionMode /// public class HtmlAttribute { - public string Key { get; set; } - public object Value { get; set; } + public string Key { get; set; } = ""; + public object? Value { get; set; } } diff --git a/src/X.PagedList.Mvc.Core/PagedListRenderOptions.cs b/src/X.PagedList.Mvc.Core/PagedListRenderOptions.cs index e2bddd27..3d9f6c79 100644 --- a/src/X.PagedList.Mvc.Core/PagedListRenderOptions.cs +++ b/src/X.PagedList.Mvc.Core/PagedListRenderOptions.cs @@ -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() ?? ""); } } diff --git a/tests/X.PagedList.Tests/TestDbAsyncQueryProvider.cs b/tests/X.PagedList.Tests/TestDbAsyncQueryProvider.cs index 4d106487..0c54579b 100644 --- a/tests/X.PagedList.Tests/TestDbAsyncQueryProvider.cs +++ b/tests/X.PagedList.Tests/TestDbAsyncQueryProvider.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; @@ -72,7 +73,7 @@ IQueryProvider IQueryable.Provider } } - internal class TestDbAsyncEnumerator : IDbAsyncEnumerator + internal class TestDbAsyncEnumerator : IDbAsyncEnumerator, IDisposable { private readonly IEnumerator _inner; @@ -86,63 +87,8 @@ public void Dispose() _inner.Dispose(); } - public Task MoveNextAsync(CancellationToken cancellationToken) - { - return Task.FromResult(_inner.MoveNext()); - } - - public T Current - { - get { return _inner.Current; } - } - - object? IDbAsyncEnumerator.Current - { - get { return Current; } - } - } - - internal class AsyncEnumerableQuery : EnumerableQuery, IDbAsyncEnumerable - { - public AsyncEnumerableQuery(IEnumerable enumerable) : base(enumerable) - { - } - - public AsyncEnumerableQuery(Expression expression) : base(expression) - { - } + public T Current => _inner.Current; - public IDbAsyncEnumerator GetAsyncEnumerator() - { - return new InMemoryDbAsyncEnumerator(((IEnumerable)this).GetEnumerator()); - } - - IDbAsyncEnumerator IDbAsyncEnumerable.GetAsyncEnumerator() - { - return GetAsyncEnumerator(); - } - - private class InMemoryDbAsyncEnumerator : IDbAsyncEnumerator - { - private readonly IEnumerator _enumerator; - - public InMemoryDbAsyncEnumerator(IEnumerator enumerator) - { - _enumerator = enumerator; - } - - public void Dispose() - { - } - - public Task MoveNextAsync(CancellationToken cancellationToken) - { - return Task.FromResult(_enumerator.MoveNext()); - } - - public T Current => _enumerator.Current; - - object? IDbAsyncEnumerator.Current => Current; - } + object? IDbAsyncEnumerator.Current => Current; } }