Skip to content
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

Fix bug in attribute convention route values #2368

Merged
merged 1 commit into from Nov 30, 2020

Conversation

habbes
Copy link
Contributor

@habbes habbes commented Nov 24, 2020

Issues

Fixes #2363

Description

Briefly describe the changes of this pull request.

Some background
Routing conventions that add values from the url to the routing convention store also keep track of the number of values added (by using the IncrementKeyCount helper method). The action selector uses this information to match the controller action with the correct number of parameters (amongst many overloads).

Current issue
The AttributeRoutingConvention adds values to routing convention store directly without using existing helper methods and did not increment the key count. This misleads the action selector to behave as if there were not keys in the url and consequently picks the Get() action without parameters over the Get(int key) action. The AttributeRoutingConvention also had an additional bug that caused it to add extra key-value pairs to the routing store, because each ODataRoute template it tried to match could insert values to the store, even if that template would not end up matching the path.

This PR fixes those issues by incrementing the key count for each value added to the convention store and clearing the values left over by route templates that did not match the current odata path.

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

@habbes habbes added the Ready for review Use this label if a pull request is ready to be reviewed label Nov 24, 2020
@@ -59,6 +59,11 @@ private AttributeRoutingConvention(string routeName)

return result;
}

// It's possible that template.TryMatch inserted values in the values dict even if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's certain ... , right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's no certain. It depends on whether TryMatch was called on path segments that have values, for example KeySegment. But if TryMatch was only called on EntitySetSegment, then it would not add values to the dict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for review Use this label if a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong endpoint be selected if 'get' action methods share the same ActionName in attribute rounting scenario
4 participants