-
Notifications
You must be signed in to change notification settings - Fork 358
Fix 'isof' and 'cast' unquoted type params issue #3117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
8acf405
Refactor
WanjohiSammy 065d26c
Remove unnecessary changes
WanjohiSammy 425b42c
Remove unnecessary whitespaces
WanjohiSammy 082a1ed
Remove whitespaces
WanjohiSammy 6162161
Remove unnecessary whitespaces
WanjohiSammy b267f82
Remove the private method and just pass the functionName as parameter
WanjohiSammy 421cbbf
Merge branch 'main' into fix/impossible-cast-with-isof-exception
WanjohiSammy 0d37d6c
nit
WanjohiSammy 41a440f
Merge branch 'fix/impossible-cast-with-isof-exception' of https://git…
WanjohiSammy 3e33ff6
Refactor
WanjohiSammy f431035
Remove unnecessary changes
WanjohiSammy c69fd1c
Remove unnecessary whitespaces
WanjohiSammy 7cf4fa7
Remove whitespaces
WanjohiSammy 53e2015
Remove unnecessary whitespaces
WanjohiSammy 6bdf585
Remove the private method and just pass the functionName as parameter
WanjohiSammy 049fae6
nit
WanjohiSammy 0679cdf
Update src/Microsoft.OData.Core/UriParser/Parsers/FunctionCallParser.cs
WanjohiSammy 5f1c503
refactor and merge with origin main
WanjohiSammy 51b1da4
Merge remote-tracking branch 'origin' into fix/impossible-cast-with-i…
WanjohiSammy 7b2a775
Use of NormalizedModelElementsCache
WanjohiSammy c5ba104
using index
WanjohiSammy 7ebd963
nit
WanjohiSammy d7e5211
using SchemaElements
WanjohiSammy 8644a6e
rename tests correctly
WanjohiSammy 04f2f61
Add NormalizedModelElementsCache singleton for EdmCoreModel and use i…
WanjohiSammy 1b7e1c6
FindSchemaTypes can return null
WanjohiSammy f219ef3
Use a lightweight stack struct
WanjohiSammy 106199f
Make StackStruct internal to avoid exposing it to the Public API
WanjohiSammy 76e644d
move StackStructOfT to Microsoft.OData namespace
WanjohiSammy a6e59a8
use explicit types
WanjohiSammy a8d7bce
Update src/Microsoft.OData.Core/UriParser/Resolver/NormalizedModelEle…
WanjohiSammy 785ac02
Use regular Stack
WanjohiSammy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -410,20 +410,26 @@ public void ParseFilterWithNullEnumValue() | |||||||||||||||||||||||||
| convertNode.Source.ShouldBeConstantQueryNode((object)null); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||
| public void ParseFilterCastMethod1() | ||||||||||||||||||||||||||
| [Theory] | ||||||||||||||||||||||||||
| [InlineData("cast(NS.Color'Green', 'Edm.String') eq 'blue'")] | ||||||||||||||||||||||||||
| [InlineData("cast(NS.Color'Green', Edm.String) eq 'blue'")] | ||||||||||||||||||||||||||
| [InlineData("cast(NS.Color'Green', edm.string) eq 'blue'")] | ||||||||||||||||||||||||||
| [InlineData("cast(NS.Color'Green', EDM.STRING) eq 'blue'")] | ||||||||||||||||||||||||||
| public void ParseFilterCastMethodWithEdmPrimitiveTypes(string filterQuery) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| var filter = ParseFilter("cast(NS.Color'Green', 'Edm.String') eq 'blue'", this.userModel, this.entityType, this.entitySet); | ||||||||||||||||||||||||||
| var filter = ParseFilter(filterQuery, true, this.userModel, this.entityType, this.entitySet); | ||||||||||||||||||||||||||
| var bon = filter.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal); | ||||||||||||||||||||||||||
| var convertNode = Assert.IsType<ConvertNode>(bon.Left); | ||||||||||||||||||||||||||
| var functionCallNode = Assert.IsType<SingleValueFunctionCallNode>(convertNode.Source); | ||||||||||||||||||||||||||
| Assert.Equal("cast", functionCallNode.Name); // ConvertNode is because cast() result's nullable=false. | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||
| public void ParseFilterCastMethod2() | ||||||||||||||||||||||||||
| [Theory] | ||||||||||||||||||||||||||
| [InlineData("cast('Green', 'NS.Color') eq NS.Color'Green'")] | ||||||||||||||||||||||||||
| [InlineData("cast('Green', NS.Color) eq NS.Color'Green'")] | ||||||||||||||||||||||||||
| public void ParseFilterCastMethodWithOrWithoutSingleQuotesOnType(string filterQuery) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| var filter = ParseFilter("cast('Green', 'NS.Color') eq NS.Color'Green'", this.userModel, this.entityType, this.entitySet); | ||||||||||||||||||||||||||
| var filter = ParseFilter(filterQuery, this.userModel, this.entityType, this.entitySet); | ||||||||||||||||||||||||||
| var bon = filter.Expression.ShouldBeBinaryOperatorNode(BinaryOperatorKind.Equal); | ||||||||||||||||||||||||||
| var functionCallNode = Assert.IsType<SingleValueFunctionCallNode>(bon.Left); | ||||||||||||||||||||||||||
| Assert.Equal("cast", functionCallNode.Name); | ||||||||||||||||||||||||||
|
|
@@ -500,17 +506,20 @@ public void ParseFilterEnumMemberUndefined4() | |||||||||||||||||||||||||
| parse.Throws<ODataException>(Error.Format(SRResources.Binder_IsNotValidEnumConstant, "NS.ColorFlags'Red,2'")); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||
| public void ParseFilterEnumTypesWrongCast1() | ||||||||||||||||||||||||||
| [Theory] | ||||||||||||||||||||||||||
| [InlineData("cast(NS.ColorFlags'Green', 'Edm.Int64') eq 2")] | ||||||||||||||||||||||||||
| [InlineData("cast(NS.ColorFlags'Green', Edm.Int64) eq 2")] | ||||||||||||||||||||||||||
| public void ParseFilterEnumTypesWrongCast1(string filter) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| Action parse = () => ParseFilter("cast(NS.ColorFlags'Green', 'Edm.Int64') eq 2", this.userModel, this.entityType, this.entitySet); | ||||||||||||||||||||||||||
| Action parse = () => ParseFilter(filter, this.userModel, this.entityType, this.entitySet); | ||||||||||||||||||||||||||
| parse.Throws<ODataException>(SRResources.CastBinder_EnumOnlyCastToOrFromString); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||
| public void ParseFilterEnumTypesWrongCast2() | ||||||||||||||||||||||||||
| [Theory] | ||||||||||||||||||||||||||
| [InlineData("cast(321, 'NS.ColorFlags') eq 2")] | ||||||||||||||||||||||||||
| [InlineData("cast(321, NS.ColorFlags) eq 2")] | ||||||||||||||||||||||||||
| public void ParseFilterEnumTypesWrongCast2(string filter) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| Action parse = () => ParseFilter("cast(321, 'NS.ColorFlags') eq 2", this.userModel, this.entityType, this.entitySet); | ||||||||||||||||||||||||||
| Action parse = () => ParseFilter(filter, this.userModel, this.entityType, this.entitySet); | ||||||||||||||||||||||||||
| parse.Throws<ODataException>(SRResources.CastBinder_EnumOnlyCastToOrFromString); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -536,7 +545,7 @@ public void ParseFilterWithInOperatorWithEnums(string filterOptionValue) | |||||||||||||||||||||||||
| IEdmEnumType colorType = this.GetIEdmType<IEdmEnumType>(colorTypeName); | ||||||||||||||||||||||||||
| IEdmEnumMember enumMember = colorType.Members.First(m => m.Name == enumValue); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| string expectedLiteral = "'Green'"; | ||||||||||||||||||||||||||
| string expectedLiteral = "'Green'"; | ||||||||||||||||||||||||||
| if (filterOptionValue.StartsWith(colorTypeName)) // if the filterOptionValue is already fully qualified, then the expectedLiteral should be the same as filterOptionValue | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| expectedLiteral = "NS.Color'Green'"; | ||||||||||||||||||||||||||
|
|
@@ -651,5 +660,11 @@ private FilterClause ParseFilter(string text, IEdmModel edmModel, IEdmEntityType | |||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return new ODataQueryOptionParser(edmModel, entityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }).ParseFilter(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private FilterClause ParseFilter(string text, bool caseInsensitive, IEdmModel edmModel, IEdmEntityType edmEntityType, IEdmEntitySet edmEntitySet) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return new ODataQueryOptionParser(edmModel, entityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }) | ||||||||||||||||||||||||||
|
Comment on lines
661
to
+666
|
||||||||||||||||||||||||||
| return new ODataQueryOptionParser(edmModel, entityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }).ParseFilter(); | |
| } | |
| private FilterClause ParseFilter(string text, bool caseInsensitive, IEdmModel edmModel, IEdmEntityType edmEntityType, IEdmEntitySet edmEntitySet) | |
| { | |
| return new ODataQueryOptionParser(edmModel, entityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }) | |
| return new ODataQueryOptionParser(edmModel, edmEntityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }).ParseFilter(); | |
| } | |
| private FilterClause ParseFilter(string text, bool caseInsensitive, IEdmModel edmModel, IEdmEntityType edmEntityType, IEdmEntitySet edmEntitySet) | |
| { | |
| return new ODataQueryOptionParser(edmModel, edmEntityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.