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 non-string "_method" in Plug.MethodOverride #1185

Merged
merged 2 commits into from
Nov 14, 2023
Merged

Conversation

whatyouhide
Copy link
Member

This fixes a bug we saw in production.

CleanShot 2023-11-14 at 09 16 25@2x

@@ -9,14 +9,33 @@ defmodule Plug.MethodOverride do
* `PATCH`
* `DELETE`

This plug expects the body parameters to be already parsed and
fetched. Those can be fetched with `Plug.Parsers`.
This plug only replaces the request method if the `_method` request
Copy link
Member Author

Choose a reason for hiding this comment

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

Cleaned up docs to be more descriptive


if method in @allowed_methods do
%{conn | method: method}
with method when is_binary(method) <- body_params["_method"] || "",
Copy link
Member Author

Choose a reason for hiding this comment

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

The fix here is the is_binary/1 guard.

@josevalim josevalim merged commit 05ca558 into main Nov 14, 2023
2 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@josevalim josevalim deleted the al/fix-method-override branch November 14, 2023 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants