Browse Source

Prevent ApiTypeNameHelper infinite loop.

pull/6065/head
maliming 6 years ago
parent
commit
b3d4f6929e
  1. 7
      framework/Volo.Abp.sln
  2. 29
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ApiTypeNameHelper.cs
  3. 16
      framework/test/Volo.Abp.Http.Tests/Volo.Abp.Http.Tests.csproj
  4. 10
      framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/AbpHttpTestModule.cs
  5. 44
      framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/ApiTypeNameHelper_Tests.cs

7
framework/Volo.Abp.sln

@ -357,6 +357,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Swashbuckle", "src
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Json.Tests", "test\Volo.Abp.Json.Tests\Volo.Abp.Json.Tests.csproj", "{00D07595-993C-40FC-BD90-0DD6331414D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Http.Tests", "test\Volo.Abp.Http.Tests\Volo.Abp.Http.Tests.csproj", "{A37BFEB5-7C57-4CDC-93B8-B5CE4BB9ACE1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -1063,6 +1065,10 @@ Global
{00D07595-993C-40FC-BD90-0DD6331414D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00D07595-993C-40FC-BD90-0DD6331414D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00D07595-993C-40FC-BD90-0DD6331414D3}.Release|Any CPU.Build.0 = Release|Any CPU
{A37BFEB5-7C57-4CDC-93B8-B5CE4BB9ACE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A37BFEB5-7C57-4CDC-93B8-B5CE4BB9ACE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A37BFEB5-7C57-4CDC-93B8-B5CE4BB9ACE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A37BFEB5-7C57-4CDC-93B8-B5CE4BB9ACE1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1243,6 +1249,7 @@ Global
{89840441-5A3A-4FD7-9CB4-E5B52FAEF72A} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{DD9519E0-5A68-48DC-A051-7BF2AC922F3E} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6}
{00D07595-993C-40FC-BD90-0DD6331414D3} = {447C8A77-E5F0-4538-8687-7383196D04EA}
{A37BFEB5-7C57-4CDC-93B8-B5CE4BB9ACE1} = {447C8A77-E5F0-4538-8687-7383196D04EA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}

29
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ApiTypeNameHelper.cs

@ -1,20 +1,28 @@
using System;
using Volo.Abp.Collections;
using Volo.Abp.Reflection;
namespace Volo.Abp.Http.Modeling
{
public static class ApiTypeNameHelper
{
private static ITypeList _cycleType = new TypeList();
public static string GetTypeName(Type type)
{
if (TypeHelper.IsDictionary(type, out var keyType, out var valueType))
{
return $"{{{GetTypeName(keyType)}:{GetTypeName(valueType)}}}";
if (keyType != type && valueType != type)
{
return $"{{{GetTypeName(keyType)}:{GetTypeName(valueType)}}}";
}
}
if (TypeHelper.IsEnumerable(type, out var itemType, includePrimitives: false))
else if (TypeHelper.IsEnumerable(type, out var itemType, includePrimitives: false))
{
return $"[{GetTypeName(itemType)}]";
if (itemType != type)
{
return $"[{GetTypeName(itemType)}]";
}
}
return TypeHelper.GetFullNameHandlingNullableAndGenerics(type);
@ -24,12 +32,17 @@ namespace Volo.Abp.Http.Modeling
{
if (TypeHelper.IsDictionary(type, out var keyType, out var valueType))
{
return $"{{{GetSimpleTypeName(keyType)}:{GetSimpleTypeName(valueType)}}}";
if (keyType != type && valueType != type)
{
return $"{{{GetSimpleTypeName(keyType)}:{GetSimpleTypeName(valueType)}}}";
}
}
if (TypeHelper.IsEnumerable(type, out var itemType, includePrimitives: false))
else if (TypeHelper.IsEnumerable(type, out var itemType, includePrimitives: false))
{
return $"[{GetSimpleTypeName(itemType)}]";
if (itemType != type)
{
return $"[{GetSimpleTypeName(itemType)}]";
}
}
return TypeHelper.GetSimplifiedName(type);

16
framework/test/Volo.Abp.Http.Tests/Volo.Abp.Http.Tests.csproj

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.test.props" />
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Abp.Http\Volo.Abp.Http.csproj" />
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
</ItemGroup>
</Project>

10
framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/AbpHttpTestModule.cs

@ -0,0 +1,10 @@
using Volo.Abp.Modularity;
namespace Volo.Abp.Http
{
[DependsOn(typeof(AbpHttpModule))]
public class AbpHttpTestModule : AbpModule
{
}
}

44
framework/test/Volo.Abp.Http.Tests/Volo/Abp/Http/ApiTypeNameHelper_Tests.cs

@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using Shouldly;
using Volo.Abp.Http.Modeling;
using Volo.Abp.Reflection;
using Xunit;
namespace Volo.Abp.Http
{
public class ApiTypeNameHelper_Tests
{
[Fact]
public void GetTypeName_Test()
{
ApiTypeNameHelper.GetTypeName(typeof(CycleClass)).ShouldBe(TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(CycleClass)));
ApiTypeNameHelper.GetTypeName(typeof(CycleClass2)).ShouldBe(TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(CycleClass2)));
}
[Fact]
public void GetSimpleTypeName_Test()
{
ApiTypeNameHelper.GetSimpleTypeName(typeof(CycleClass)).ShouldBe(TypeHelper.GetSimplifiedName(typeof(CycleClass)));
ApiTypeNameHelper.GetSimpleTypeName(typeof(CycleClass2)).ShouldBe(TypeHelper.GetSimplifiedName(typeof(CycleClass2)));
}
class CycleClass : IEnumerable<CycleClass>
{
public IEnumerator<CycleClass> GetEnumerator()
{
yield return new CycleClass();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
class CycleClass2 : Dictionary<CycleClass2, CycleClass2>
{
}
}
}
Loading…
Cancel
Save