Fix items found in PVS-Studio analysis
This commit is contained in:
committed by
Nathan Woulfe
parent
d1f1817744
commit
7f9b143e1a
@@ -49,6 +49,7 @@ namespace Umbraco.Cms.Core.Configuration.Models
|
||||
if (!ModelsMode.IsAuto())
|
||||
{
|
||||
_flagOutOfDateModels = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_flagOutOfDateModels = value;
|
||||
|
||||
@@ -626,7 +626,6 @@ namespace Umbraco.Extensions
|
||||
if (type == typeof(sbyte)) return XmlConvert.ToString((sbyte)value);
|
||||
if (type == typeof(short)) return XmlConvert.ToString((short)value);
|
||||
if (type == typeof(TimeSpan)) return XmlConvert.ToString((TimeSpan)value);
|
||||
if (type == typeof(bool)) return XmlConvert.ToString((bool)value);
|
||||
if (type == typeof(uint)) return XmlConvert.ToString((uint)value);
|
||||
if (type == typeof(ulong)) return XmlConvert.ToString((ulong)value);
|
||||
if (type == typeof(ushort)) return XmlConvert.ToString((ushort)value);
|
||||
|
||||
@@ -269,16 +269,10 @@ namespace Umbraco.Extensions
|
||||
|
||||
if (!pcr.HasPublishedContent())
|
||||
{
|
||||
var logMsg = nameof(DetectCollisionAsync) +
|
||||
const string logMsg = nameof(DetectCollisionAsync) +
|
||||
" did not resolve a content item for original url: {Url}, translated to {TranslatedUrl} and culture: {Culture}";
|
||||
if (pcr.IgnorePublishedContentCollisions)
|
||||
{
|
||||
logger.LogDebug(logMsg, url, uri, culture);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogDebug(logMsg, url, uri, culture);
|
||||
}
|
||||
|
||||
logger.LogDebug(logMsg, url, uri, culture);
|
||||
|
||||
var urlInfo = UrlInfo.Message(textService.Localize("content", "routeErrorCannotRoute"), culture);
|
||||
return Attempt.Succeed(urlInfo);
|
||||
|
||||
@@ -468,7 +468,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Querying
|
||||
case nameof(StringExtensions.InvariantStartsWith):
|
||||
case nameof(StringExtensions.InvariantEndsWith):
|
||||
case nameof(StringExtensions.InvariantContains):
|
||||
case nameof(StringExtensions.InvariantEquals):
|
||||
case nameof(StringExtensions.InvariantEquals):
|
||||
|
||||
string compareValue;
|
||||
|
||||
@@ -629,7 +629,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Querying
|
||||
if (m.Arguments.Count == 2)
|
||||
{
|
||||
var n1 = Visit(m.Arguments[0]);
|
||||
var f = m.Arguments[2];
|
||||
var f = m.Arguments[1];
|
||||
if (!(f is Expression<Func<string, string>> fl))
|
||||
throw new NotSupportedException("Expression is not a proper lambda.");
|
||||
var ff = fl.Compile();
|
||||
|
||||
@@ -760,27 +760,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
if (id == Constants.System.Root && startNodes.Length > 0 &&
|
||||
startNodes.Contains(Constants.System.Root) == false && !ignoreUserStartNodes)
|
||||
{
|
||||
if (pageNumber > 0)
|
||||
{
|
||||
return new PagedResult<EntityBasic>(0, 0, 0);
|
||||
}
|
||||
|
||||
IEntitySlim[] nodes = _entityService.GetAll(objectType.Value, startNodes).ToArray();
|
||||
if (nodes.Length == 0)
|
||||
{
|
||||
return new PagedResult<EntityBasic>(0, 0, 0);
|
||||
}
|
||||
|
||||
if (pageSize < nodes.Length)
|
||||
{
|
||||
pageSize = nodes.Length; // bah
|
||||
}
|
||||
|
||||
var pr = new PagedResult<EntityBasic>(nodes.Length, pageNumber, pageSize)
|
||||
{
|
||||
Items = nodes.Select(_umbracoMapper.Map<EntityBasic>)
|
||||
};
|
||||
return pr;
|
||||
return new PagedResult<EntityBasic>(0, 0, 0);
|
||||
}
|
||||
|
||||
// else proceed as usual
|
||||
|
||||
@@ -479,7 +479,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
{
|
||||
if (userSave == null)
|
||||
{
|
||||
throw new ArgumentNullException("userSave");
|
||||
throw new ArgumentNullException(nameof(userSave));
|
||||
}
|
||||
|
||||
if (userSave.Message.IsNullOrWhiteSpace())
|
||||
@@ -487,7 +487,6 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
ModelState.AddModelError("Message", "Message cannot be empty");
|
||||
}
|
||||
|
||||
IUser user;
|
||||
if (_securitySettings.UsernameIsEmail)
|
||||
{
|
||||
// ensure it's the same
|
||||
@@ -496,16 +495,14 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
|
||||
else
|
||||
{
|
||||
// first validate the username if we're showing it
|
||||
var userResult = CheckUniqueUsername(userSave.Username, u => u.LastLoginDate != default || u.EmailConfirmedDate.HasValue);
|
||||
if (!(userResult.Result is null))
|
||||
ActionResult<IUser> userResult = CheckUniqueUsername(userSave.Username, u => u.LastLoginDate != default || u.EmailConfirmedDate.HasValue);
|
||||
if (userResult.Result is not null)
|
||||
{
|
||||
return userResult.Result;
|
||||
}
|
||||
|
||||
user = userResult.Value;
|
||||
}
|
||||
|
||||
user = CheckUniqueEmail(userSave.Email, u => u.LastLoginDate != default || u.EmailConfirmedDate.HasValue);
|
||||
IUser user = CheckUniqueEmail(userSave.Email, u => u.LastLoginDate != default || u.EmailConfirmedDate.HasValue);
|
||||
|
||||
if (ModelState.IsValid == false)
|
||||
{
|
||||
|
||||
@@ -195,7 +195,8 @@ namespace Umbraco.Cms.Web.Common.Routing
|
||||
var routeValues = new RouteValueDictionary();
|
||||
|
||||
// To get the matchedEndpoint of the provide url
|
||||
RouteEndpoint matchedEndpoint = routeEndpoints
|
||||
RouteEndpoint matchedEndpoint = routeEndpoints?
|
||||
.Where(e => e.RoutePattern.RawText != null)
|
||||
.Where(e => new TemplateMatcher(
|
||||
TemplateParser.Parse(e.RoutePattern.RawText),
|
||||
new RouteValueDictionary())
|
||||
|
||||
@@ -73,8 +73,6 @@ namespace Umbraco.Cms.Web.Common.Security
|
||||
}
|
||||
else
|
||||
{
|
||||
string username;
|
||||
|
||||
MemberIdentityUser currentMember = await GetCurrentMemberAsync();
|
||||
|
||||
// If a member could not be resolved from the provider, we are clearly not authorized and can break right here
|
||||
@@ -84,7 +82,6 @@ namespace Umbraco.Cms.Web.Common.Security
|
||||
}
|
||||
|
||||
int memberId = int.Parse(currentMember.Id, CultureInfo.InvariantCulture);
|
||||
username = currentMember.UserName;
|
||||
|
||||
// If types defined, check member is of one of those types
|
||||
IList<string> allowTypesList = allowTypes as IList<string> ?? allowTypes.ToList();
|
||||
@@ -95,10 +92,11 @@ namespace Umbraco.Cms.Web.Common.Security
|
||||
}
|
||||
|
||||
// If specific members defined, check member is of one of those
|
||||
if (allowAction && allowMembers.Any())
|
||||
var allowMembersList = allowMembers.ToList();
|
||||
if (allowAction && allowMembersList.Any())
|
||||
{
|
||||
// Allow only if member's Id is in the list
|
||||
allowAction = allowMembers.Contains(memberId);
|
||||
allowAction = allowMembersList.Contains(memberId);
|
||||
}
|
||||
|
||||
// If groups defined, check member is of one of those groups
|
||||
@@ -118,7 +116,7 @@ namespace Umbraco.Cms.Web.Common.Security
|
||||
public bool IsLoggedIn()
|
||||
{
|
||||
HttpContext httpContext = _httpContextAccessor.HttpContext;
|
||||
return httpContext?.User != null && httpContext.User.Identity.IsAuthenticated;
|
||||
return httpContext?.User.Identity?.IsAuthenticated ?? false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user