Skip to content

Commit

Permalink
Hotfix for the infinite loop if structured type has property which ty…
Browse files Browse the repository at this point in the history
…pe is the declaring type
  • Loading branch information
xuzhg committed Aug 13, 2020
1 parent 2483873 commit 579dc04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,21 @@ private void ValidateImpliedProperties(IEdmType segmentType, SelectExpandClause
// Validate all structured properties of a type, recursing through nested complex typed properties
private void ValidateProperties(IEdmType edmType, ODataUrlValidationContext context)
{
IEdmStructuredType structuredType = edmType as IEdmStructuredType;
if (structuredType != null)
if (!context.ValidatedTypes.Contains(edmType))
{
foreach (IEdmProperty property in structuredType.StructuralProperties())
context.ValidatedTypes.Add(edmType);

IEdmStructuredType structuredType = edmType as IEdmStructuredType;
if (structuredType != null)
{
ValidateItem(property, context, /* impliedProperty */ true);
ValidateItem(property.Type.Definition.AsElementType(), context, /* impliedProperty */ true);
ValidateProperties(property.Type.Definition.AsElementType(), context);
foreach (IEdmProperty property in structuredType.StructuralProperties())
{
IEdmType elementType = property.Type.Definition.AsElementType();

ValidateItem(property, context, /* impliedProperty */ true);
ValidateItem(elementType, context, /* impliedProperty */ true);
ValidateProperties(elementType, context);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public class DeprecationTests
private static IEdmModel model;

[Theory]
[InlineData(@"company", "name","state")]
[InlineData(@"company", "name", "state")]
[InlineData(@"company/employees", "employees")]
[InlineData(@"competitors", "competitors", "name", "state")]
[InlineData(@"company/address", "state")]
[InlineData(@"company/address/state", "state")]
[InlineData(@"company/address?$select=state", "state")]
[InlineData(@"company?$expand=employees", "name", "state", "employees")]
[InlineData(@"company?$select=name", "name")]
[InlineData(@"competitors?$filter=contains(name,'sprocket')", "competitors", "name","state","name")]
[InlineData(@"competitors?$filter=contains(name,'sprocket')", "competitors", "name", "state", "name")]
public static void WithDeprecatedElementsGeneratesErrors(String request, params string[] expectedErrors)
{
string expectedDateAsString = "2020-03-30";
Expand Down Expand Up @@ -108,6 +108,7 @@ private static IEdmModel GetModel()
<Schema xmlns = ""http://docs.oasis-open.org/odata/ns/edm"" Namespace=""Jetsons.Models"">
<ComplexType Name = ""address"" >
<Property Name=""city"" Type=""Edm.String""/>
<Property Name=""subAddress"" Type=""Jetsons.Models.address""/>
<Property Name = ""state"" Type=""Edm.String"">
<Annotation Term = ""Core.Revisions"" >
<Collection>
Expand Down

0 comments on commit 579dc04

Please sign in to comment.