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(core): prevent exclude method from overwriting previous calls #13614

Conversation

dragontaek-lee
Copy link
Contributor

@dragontaek-lee dragontaek-lee commented May 25, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

Summary:

Previously, calling multiple exclude method in MiddlewareConsumer overwrote the previously excluded routes.

configure(consumer: MiddlewareConsumer) {
    consumer
      .apply((req, res, next) => res.send(MIDDLEWARE_VALUE))
      .exclude('test', 'overview/:id', 'wildcard/(.*)', {
          path: 'middleware',
          method: RequestMethod.POST,
       }) // ignored
      .exclude('multiple/exclude')
      .forRoutes('*');
 }

It only worked well when using a single exclude method.

configure(consumer: MiddlewareConsumer) {
    consumer
      .apply((req, res, next) => res.send(MIDDLEWARE_VALUE))
      .exclude('test', 'overview/:id', 'wildcard/(.*)', 'multiple/exclude', {
        path: 'middleware',
        method: RequestMethod.POST,
      })
      .forRoutes('*');
}

I created a minimum reproduction repository.

Both repositories contain the same code. You can review the test code (exclude-middleware.spec.ts) and see the results by cloning or forking the repository and running npm run test.

What is the new behavior?

This change ensures that the exclude method appends new routes to the existing excluded routes list instead of overwriting them.
This preserves all previous exclude calls and maintains the intended behavior of accumulating excluded routes.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coveralls
Copy link

Pull Request Test Coverage Report for Build 5967bb56-11c2-444f-9474-e996881d3e45

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.124%

Totals Coverage Status
Change from base Build 94cfa8c0-2cff-488c-b4b7-6f54fde1b9de: 0.0%
Covered Lines: 6737
Relevant Lines: 7313

💛 - Coveralls

Copy link

@ajlchiban ajlchiban left a comment

Choose a reason for hiding this comment

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

No comment

@ajlchiban
Copy link

Can not use terminal to sudo

@dragontaek-lee
Copy link
Contributor Author

dragontaek-lee commented May 26, 2024

Hello @ajlchiban,

Thank you for your response. Did you mean that you couldn't use the terminal to run sudo commands in the CodeSandbox? I thought anyone could use the terminal to sudo by forking the public project.

To avoid any confusion, I've added a minimum reproduction repository on GitHub as well.

@kamilmysliwiec
Copy link
Member

lgtm

@kamilmysliwiec kamilmysliwiec merged commit de86355 into nestjs:master Jun 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants