nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: phoenixframework/phoenix
Pull request #4173 (2021-01-25 05:14:35)

Use reuse instead of re-use


Patch:
diff --git a/guides/controllers.md b/guides/controllers.md
index e1d166531..6f27eb06f 100644
--- a/guides/controllers.md
+++ b/guides/controllers.md
@@ -416,7 +416,7 @@ Fortunately, our application layout, `lib/hello_web/templates/layout/app.html.ee
 
 When we reload the [Welcome Page](http://localhost:4000/), our messages should appear just above "Welcome to Phoenix!"
 
-The flash functionality is handy when mixed with redirects. Perhaps you want to redirect to a page with some extra information. If we re-use the redirect action from the previous section, we can do:
+The flash functionality is handy when mixed with redirects. Perhaps you want to redirect to a page with some extra information. If we reuse the redirect action from the previous section, we can do:
 
 ```elixir
   def index(conn, _params) do
diff --git a/guides/request_lifecycle.md b/guides/request_lifecycle.md
index a27ff073d..568f8bb87 100644
--- a/guides/request_lifecycle.md
+++ b/guides/request_lifecycle.md
@@ -188,7 +188,7 @@ As we did last time, the first thing we'll do is create a new route.
 
 ### Another new Route
 
-For this exercise, we're going to re-use the `HelloController` we just created and just add a new `show` action. We'll add a line just below our last route, like this:
+For this exercise, we're going to reuse the `HelloController` we just created and just add a new `show` action. We'll add a line just below our last route, like this:
 
 ```elixir
 scope "/", HelloWeb do


Test patch:
diff --git a/guides/testing/testing_channels.md b/guides/testing/testing_channels.md
index 7a0a398cb..e996d7874 100644
--- a/guides/testing/testing_channels.md
+++ b/guides/testing/testing_channels.md
@@ -77,7 +77,7 @@ setup do
 end
 ```
 
-The `setup` block sets up a `Phoenix.Socket` based on the `UserSocket` module, which you can find at "lib/hello_web/channels/user_socket.ex". Then it says we want to subscribe and join the `RoomChannel`, accessible as "room:lobby" in the `UserSocket`. At the end of the test, we return the `%{socket: socket}` as metadata, so we can re-use it on every test.
+The `setup` block sets up a `Phoenix.Socket` based on the `UserSocket` module, which you can find at "lib/hello_web/channels/user_socket.ex". Then it says we want to subscribe and join the `RoomChannel`, accessible as "room:lobby" in the `UserSocket`. At the end of the test, we return the `%{socket: socket}` as metadata, so we can reuse it on every test.
 
 In a nutshell, `subscribe_and_join/3` emulates the client joining a channel and subscribes the test process to the given topic. This is a necessary step since clients need to join a channel before they can send and receive events on that channel.
Repository: phoenixframework/phoenix
Pull request #4273 (2021-03-23 17:53:28)

Add .map to gzippable extensions
This pull request adds the `.map` extension to the list of _gzippable extensions_.

This is mostly a matter of consistency rather than performance.

### Before running `mix phx.digest`

```
priv/static
├── css
│  └── app.css
├── js
│  ├── app.js
│  └── app.js.map
```

### After running `mix phx.digest`

```
priv/static
├── cache_manifest.json
├── css
│  ├── app-c60f329d5f7165fe3b7016ba48b7252f.css
│  ├── app-c60f329d5f7165fe3b7016ba48b7252f.css.gz
│  ├── app.css
│  └── app.css.gz
├── js
│  ├── app-a3f59890277c10a37e518d3f4e19fb7e.js
│  ├── app-a3f59890277c10a37e518d3f4e19fb7e.js.gz
│  ├── app.js
│  ├── app.js-1d02813ec397c786ae3c97473218f5e0.map # ← Not gzipped
│  ├── app.js.gz
│  └── app.js.map # ← Also not gzipped
```

I think it would be a safe default to assume that if Phoenix generates source maps by default, that they should also be included in the _gzipping_ process.

Let me know if this is a good idea or not 🙂


remi: I’m not sure why the CI check is failing randomly 😞 It doesn’t seem related to my changes.

```
+test *failed* |   1) test adapters starts on configured port and serves requests and stops for dev (Phoenix.Integration.EndpointTest)
+test *failed* |      test/phoenix/integration/endpoint_test.exs:160
+test *failed* |      ** (EXIT from #PID<0.5026.0>) shutdown: failed to start child: {:ranch_listener_sup, Phoenix.Integration.AdapterTest.DevEndpoint.HTTP}
```

Patch:
diff --git a/mix.exs b/mix.exs
index d7ba09851..63bdbe404 100644
--- a/mix.exs
+++ b/mix.exs
@@ -52,7 +52,7 @@ defmodule Phoenix.MixProject do
         stacktrace_depth: nil,
         filter_parameters: ["password"],
         serve_endpoints: false,
-        gzippable_exts: ~w(.js .css .txt .text .html .json .svg .eot .ttf),
+        gzippable_exts: ~w(.js .map .css .txt .text .html .json .svg .eot .ttf),
         static_compressors: [Phoenix.Digester.Gzip]
       ]
     ]


Test patch:
diff --git a/test/phoenix/digester_test.exs b/test/phoenix/digester_test.exs
index 12cccaf8b..78594f2e6 100644
--- a/test/phoenix/digester_test.exs
+++ b/test/phoenix/digester_test.exs
@@ -24,6 +24,8 @@ defmodule Phoenix.DigesterTest do
       refute "phoenix.png.gz" in output_files
       assert "app.js" in output_files
       assert "app.js.gz" in output_files
+      assert "app.js.map" in output_files
+      assert "app.js.map.gz" in output_files
       assert "css/app.css" in output_files
       assert "css/app.css.gz" in output_files
       assert "manifest.json" in output_files
Repository: phoenixframework/phoenix
Pull request #4322 (2021-05-12 03:23:09)

Implement Phoenix.Param for Float
I tried to place a float in the query string of a URL using the router helpers like this:

```elixir
latitude = 32.149989
longitude = -110.835842
MyAppWeb.Router.Helpers.page_path(:search, %{latitude: latitude, longitude: longitude})
```

But I get the error

```
** (Protocol.UndefinedError) protocol Phoenix.Param not implemented for 32.149989 of type Float. This protocol is implemented for the following type(s): Any, Map, Integer, BitString, Atom
```

I've implemented this in my own application, but I felt like Float is a common enough data structure that it would make sense for me to add this change back upstream for everyone else too. I'm happy to make any changes necessary.


Patch:
diff --git a/lib/phoenix/param.ex b/lib/phoenix/param.ex
index 8a51ffcf5..7ccd2b767 100644
--- a/lib/phoenix/param.ex
+++ b/lib/phoenix/param.ex
@@ -58,6 +58,10 @@ defimpl Phoenix.Param, for: Integer do
   def to_param(int), do: Integer.to_string(int)
 end
 
+defimpl Phoenix.Param, for: Float do
+  def to_param(float), do: Float.to_string(float)
+end
+
 defimpl Phoenix.Param, for: BitString do
   def to_param(bin) when is_binary(bin), do: bin
 end


Test patch:
diff --git a/test/phoenix/param_test.exs b/test/phoenix/param_test.exs
index eb36fed9d..8b392cec4 100644
--- a/test/phoenix/param_test.exs
+++ b/test/phoenix/param_test.exs
@@ -7,6 +7,10 @@ defmodule Phoenix.ParamTest do
     assert to_param(1) == "1"
   end
 
+  test "to_param for floats" do
+    assert to_param(3.14) == "3.14"
+  end
+
   test "to_param for binaries" do
     assert to_param("foo") == "foo"
   end
@@ -52,4 +56,4 @@ defmodule Phoenix.ParamTest do
       to_param(struct(Bar, uuid: nil))
     end
   end
-end
\ No newline at end of file
+end
Repository: phoenixframework/phoenix
Pull request #3613 (2019-11-14 20:17:01)

Fix `ConnTest` and `Contributing` typos
Please see commits


Patch:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 6a0128722..f58ab774f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -207,7 +207,7 @@ of beginning users because expert users have more tools at their disposal to
 help themselves.
 
 The general pattern we use for presenting information is to first introduce a
-small, discreet topic, then write a small amount of code to demonstrate the
+small, discrete topic, then write a small amount of code to demonstrate the
 concept, then verify that the code worked.
 
 In this way, we build from small, easily digestible concepts into more complex


Test patch:
diff --git a/lib/phoenix/test/conn_test.ex b/lib/phoenix/test/conn_test.ex
index 54e4b0e1c..783921378 100644
--- a/lib/phoenix/test/conn_test.ex
+++ b/lib/phoenix/test/conn_test.ex
@@ -369,7 +369,7 @@ defmodule Phoenix.ConnTest do
   end
 
   @doc """
-  Asserts the given status code, that we have an text response and
+  Asserts the given status code, that we have a text response and
   returns the response body if one was set or sent.
 
   ## Examples
@@ -384,7 +384,7 @@ defmodule Phoenix.ConnTest do
   end
 
   @doc """
-  Asserts the given status code, that we have an json response and
+  Asserts the given status code, that we have a json response and
   returns the decoded JSON response if one was set or sent.
 
   ## Examples
@@ -542,7 +542,7 @@ defmodule Phoenix.ConnTest do
   end
 
   @doc """
-  Calls the Endpoint and and the given Router pipelines.
+  Calls the Endpoint and the given Router pipelines.
 
   See `bypass_through/1`.
   """
Repository: phoenixframework/phoenix
Pull request #3648 (2020-01-10 19:52:42)

Fix typo in `test/conn_test.ex`
Just what it says in the title! 😄 


Patch:
diff --git a/guides/deployment/heroku.md b/guides/deployment/heroku.md
index d6236749d..9c41d0276 100644
--- a/guides/deployment/heroku.md
+++ b/guides/deployment/heroku.md
@@ -131,7 +131,7 @@ Finally, note that since we are using multiple buildpacks, you might run into an
 
 Every new Phoenix project ships with a config file `config/prod.secret.exs` which loads configuration and secrets from [environment variables](https://devcenter.heroku.com/articles/config-vars). This aligns well with Heroku best practices, so most the only work left for us to do is to configure URLs and SSL.
 
-First let's tell Phoenix to use our Heroku URL and enforce we only use the SSL version of the website. Find the url line in your `config/prod.exs`:
+First let's tell Phoenix to use our Heroku URL and enforce we only use the SSL version of the website. Also, bind to the port requested by Heroku in the [`$PORT` environment variable](https://devcenter.heroku.com/articles/runtime-principles#web-servers). Find the url line in your `config/prod.exs`:
 
 ```elixir
 url: [host: "example.com", port: 80],
@@ -140,6 +140,7 @@ url: [host: "example.com", port: 80],
 ... and replace it with this (don't forget to replace `mysterious-meadow-6277` with your application name):
 
 ```elixir
+http: [port: {:system, "PORT"}],
 url: [scheme: "https", host: "mysterious-meadow-6277.herokuapp.com", port: 443],
 force_ssl: [rewrite_on: [:x_forwarded_proto]],
 ```


Test patch:
diff --git a/lib/phoenix/test/conn_test.ex b/lib/phoenix/test/conn_test.ex
index 783921378..0e7466109 100644
--- a/lib/phoenix/test/conn_test.ex
+++ b/lib/phoenix/test/conn_test.ex
@@ -487,7 +487,7 @@ defmodule Phoenix.ConnTest do
 
   Note the use of `get("/")` following `bypass_through` in the examples below.
   To execute the plug pipelines, you must issue a request against the router.
-  Most often, you can simpy send a GET request against the root path, but you
+  Most often, you can simply send a GET request against the root path, but you
   may also specify a different method or path which your pipelines may operate
   against.
Repository: phoenixframework/phoenix
Pull request #4649 (2021-12-26 07:04:17)

Fix broken `check_origin: :conn`
In the internal implementation, the related function is at [here](https://github.com/phoenixframework/phoenix/blob/8d2b33ac9691bd624ede602088d213f89600d233/lib/phoenix/socket/transport.ex#L596):

```elixir
defp origin_allowed?(:conn, uri, _endpoint, %Plug.Conn{} = conn)
```

`uri` is a struct which is generated by `URI.parse/1`, the type of `scheme`
field is a string.

`conn` is a `%Plug.Conn{}`, the type of `scheme` field is an atom.

Because of that, this check will always failed in real case.

* * *

This commit fixes above issue, and fix related tests.


Patch:
diff --git a/lib/phoenix/socket/transport.ex b/lib/phoenix/socket/transport.ex
index 2f1d113a4..646e6d109 100644
--- a/lib/phoenix/socket/transport.ex
+++ b/lib/phoenix/socket/transport.ex
@@ -593,8 +593,13 @@ defmodule Phoenix.Socket.Transport do
 
   defp origin_allowed?({module, function, arguments}, uri, _endpoint, _conn),
     do: apply(module, function, [uri | arguments])
-  defp origin_allowed?(:conn, uri, _endpoint, %Plug.Conn{} = conn),
-    do: uri.host == conn.host and uri.scheme == conn.scheme and uri.port == conn.port
+
+  defp origin_allowed?(:conn, uri, _endpoint, %Plug.Conn{} = conn) do
+    uri.host == conn.host and
+      uri.scheme == Atom.to_string(conn.scheme) and
+      uri.port == conn.port
+  end
+
   defp origin_allowed?(_check_origin, %{host: nil}, _endpoint, _conn),
     do: false
   defp origin_allowed?(true, uri, endpoint, _conn),


Test patch:
diff --git a/test/phoenix/socket/transport_test.exs b/test/phoenix/socket/transport_test.exs
index da8c15b70..4f1d794fa 100644
--- a/test/phoenix/socket/transport_test.exs
+++ b/test/phoenix/socket/transport_test.exs
@@ -133,8 +133,8 @@ defmodule Phoenix.Socket.TransportTest do
       refute check_origin("", check_origin: mfa).halted
     end
 
-    test "checks origin against :host" do
-      conn = %Plug.Conn{conn(:get, "/") | host: "example.com", scheme: "http", port: 80}
+    test "checks origin against :conn" do
+      conn = %Plug.Conn{conn(:get, "/") | host: "example.com", scheme: :http, port: 80}
       refute check_origin(conn, "http://example.com", check_origin: :conn).halted
 
       assert check_origin(conn, "https://example.com", check_origin: :conn).halted
@@ -143,7 +143,7 @@ defmodule Phoenix.Socket.TransportTest do
       assert check_origin(conn, "http://www.example.com", check_origin: :conn).halted
       assert check_origin(conn, "http://www.another.com", check_origin: :conn).halted
 
-      conn = %Plug.Conn{conn(:get, "/") | host: "example.com", scheme: "https", port: 443}
+      conn = %Plug.Conn{conn(:get, "/") | host: "example.com", scheme: :https, port: 443}
       refute check_origin(conn, "https://example.com", check_origin: :conn).halted
       assert check_origin(conn, "http://example.com", check_origin: :conn).halted
       assert check_origin(conn, "https://example.com:4000", check_origin: :conn).halted