-
Notifications
You must be signed in to change notification settings - Fork 349
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
Do not fail if parenthesis are not in expected state #2828
base: release-7.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,30 +36,72 @@ public void CallbackReturnsBatchReferenceSegment() | |
|
||
[Fact] | ||
public void RequestUriProcessorExtractSegmentIdentifierTest() | ||
{ | ||
ExtractSegmentIdentifierAndParenthesisExpression("blah", "blah", null); | ||
ExtractSegmentIdentifierAndParenthesisExpression("multiple words", "multiple words", null); | ||
ExtractSegmentIdentifierAndParenthesisExpression("multiple(123)", "multiple", "123"); | ||
ExtractSegmentIdentifierAndParenthesisExpression("multiple(123;321)", "multiple", "123;321"); | ||
ExtractSegmentIdentifierAndParenthesisExpression("set()", "set", string.Empty); | ||
} | ||
|
||
[Fact] | ||
public void RequestUriProcessorExtractSegmentIdentifierErrorTest() | ||
{ | ||
string actualIdentifier; | ||
string queryPortion; | ||
|
||
Action emptyString = () => ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression(string.Empty, out actualIdentifier, out queryPortion); | ||
// Success cases | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: false, "blah", "blah", null); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: false, "multiple words", "multiple words", null); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: false, "multiple(123)", "multiple", "123"); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: false, "multiple(123;321)", "multiple", "123;321"); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: false, "set()", "set", string.Empty); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test case for a scenario that does not contain an |
||
|
||
// Failure cases | ||
Action emptyString = | ||
() => | ||
ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression( | ||
enableKeyAsSegment: false, | ||
string.Empty, | ||
out actualIdentifier, | ||
out queryPortion); | ||
emptyString.Throws<ODataUnrecognizedPathException>(ErrorStrings.RequestUriProcessor_EmptySegmentInRequestUrl); | ||
|
||
Action noIdentifier = () => ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression("()", out actualIdentifier, out queryPortion); | ||
Action noIdentifier = | ||
() => | ||
ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression( | ||
enableKeyAsSegment: false, | ||
"()", | ||
out actualIdentifier, | ||
out queryPortion); | ||
noIdentifier.Throws<ODataUnrecognizedPathException>(ErrorStrings.RequestUriProcessor_EmptySegmentInRequestUrl); | ||
|
||
Action noEndParen = () => ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression("foo(", out actualIdentifier, out queryPortion); | ||
Action noEndParen = | ||
() => | ||
ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression( | ||
enableKeyAsSegment: false, | ||
"foo(", | ||
out actualIdentifier, | ||
out queryPortion); | ||
noEndParen.Throws<ODataException>(ErrorStrings.RequestUriProcessor_SyntaxError); | ||
} | ||
|
||
[Fact] | ||
public void RequestUriProcessorExtractSegmentIdentifierTest_KeyAsSegment() | ||
{ | ||
string actualIdentifier; | ||
string queryPortion; | ||
|
||
// Success cases | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: true, "blah", "blah", null); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: true, "multiple words", "multiple words", null); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: true, "multiple(123)", "multiple", "123"); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: true, "multiple(123;321)", "multiple", "123;321"); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: true, "set()", "set", string.Empty); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: true, "()", "()", null); | ||
ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment: true, "foo(", "foo(", null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test case for a scenario that does not contain an Also, is it a good idea to support different syntaxes depending on whether key as segment is enabled? |
||
|
||
// Failure cases | ||
Action emptyString = | ||
() => | ||
ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression( | ||
enableKeyAsSegment: false, | ||
string.Empty, | ||
out actualIdentifier, | ||
out queryPortion); | ||
emptyString.Throws<ODataUnrecognizedPathException>(ErrorStrings.RequestUriProcessor_EmptySegmentInRequestUrl); | ||
} | ||
|
||
#region $ref cases | ||
[Fact] | ||
public void EntityReferenceFollowingEntityCollectionShouldWork() | ||
|
@@ -811,11 +853,15 @@ public void ParseBoundFunctionWithTypeDefinitionAsParameterAndReturnTypeShouldWo | |
Assert.Equal("abc", node.Value); | ||
} | ||
|
||
private static void ExtractSegmentIdentifierAndParenthesisExpression(string segment, string expectedIdentifier, string expectedQueryPortion) | ||
private static void ExtractSegmentIdentifierAndParenthesisExpression( | ||
bool enableKeyAsSegment, | ||
string segment, | ||
string expectedIdentifier, | ||
string expectedQueryPortion) | ||
{ | ||
string actualIdentifier; | ||
string queryPortion; | ||
ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression(segment, out actualIdentifier, out queryPortion); | ||
ODataPathParser.ExtractSegmentIdentifierAndParenthesisExpression(enableKeyAsSegment, segment, out actualIdentifier, out queryPortion); | ||
Assert.Equal(expectedIdentifier, actualIdentifier); | ||
Assert.Equal(expectedQueryPortion, queryPortion); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -377,7 +377,7 @@ public void ErrorParameterTemplateInputShouldThrow() | |
new {Input = "}{" , Error = Strings.ExpressionLexer_InvalidCharacter("}", 6, "onCat=}{")}, | ||
new {Input = "{{}" , Error = Strings.ExpressionLexer_UnbalancedBracketExpression}, // Thrown by ODataPathParser::TryBindingParametersAndMatchingOperation | ||
new {Input = "{}}" , Error = Strings.ExpressionLexer_InvalidCharacter("}", 8, "onCat={}}")}, | ||
new {Input = "{#}" , Error = Strings.RequestUriProcessor_SyntaxError}, | ||
new {Input = "{#}" , Error = Strings.RequestUriProcessor_ResourceNotFound("Fully.Qualified.Namespace.HasHat(onCat={")}, | ||
}; | ||
|
||
foreach (var errorCase in errorCases) | ||
|
@@ -388,7 +388,7 @@ public void ErrorParameterTemplateInputShouldThrow() | |
}; | ||
|
||
Action action = () => uriParser.ParsePath(); | ||
action.Throws<ODataException>(errorCase.Error); | ||
action.ThrowsAny<ODataException>(errorCase.Error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between |
||
} | ||
} | ||
|
||
|
@@ -403,7 +403,7 @@ public void ErrorKeyTemplateInputShouldThrow() | |
new {Input = "}{" , Error = Strings.ExpressionLexer_InvalidCharacter("}", 1, "(}{)")}, | ||
new {Input = "{{}" , Error = Strings.ExpressionLexer_UnbalancedBracketExpression}, // Thrown by ODataPathParser::TryBindKeyFromParentheses | ||
new {Input = "{}}" , Error = Strings.ExpressionLexer_InvalidCharacter("}", 3, "({}})")}, | ||
new {Input = "{#}" , Error = Strings.RequestUriProcessor_SyntaxError}, | ||
new {Input = "{#}" , Error = Strings.RequestUriProcessor_ResourceNotFound("People({")}, | ||
}; | ||
|
||
foreach (var errorCase in errorCases) | ||
|
@@ -414,7 +414,7 @@ public void ErrorKeyTemplateInputShouldThrow() | |
}; | ||
|
||
Action action = () => uriParser.ParsePath(); | ||
action.Throws<ODataException>(errorCase.Error); | ||
action.ThrowsAny<ODataException>(errorCase.Error); | ||
} | ||
} | ||
#endregion | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this condition consistent with existing behaviour?
In the current behaviour, if the segment does not contain and open parenthesis but ends with closing parenthesis, e.g.
folder)
, the condition would pass and theidentifier
would be set to thesegmentText
.However, in your change, if the segment does not contain an open parenthesis but ends with closing parenthesis, the condition would fail when
enableKeyAsSegment
is false and a segment likefolder)
would throw an error.