jacksonh / manos

Manos is an easy to use, easy to test, high performance web application framework that stays out of your way and makes your life ridiculously simple.
Other
455 stars 61 forks source link

HttpFormPostHandler does not handle empty input value correctly #44

Closed atsushieno closed 13 years ago

atsushieno commented 13 years ago

manos does not handle form entries when there is an empty input text.

Repro:

1) manos -init foobar 2) Add the following methods in foobar.cs

            [Route ("/")]
            public void Index (IManosContext ctx)
            {
                    ctx.Response.End (@"
"); } ``` [Route ("/a")] public void ProcessPost (IManosContext ctx) { ctx.Response.End ("x = {0}, y = {1}", ctx.Request.Data ["x"], ctx.Request.Data ["y"]); } ``` 3) manos -build 4) manos -server 5) Open http://localhost:8080/ 6) Enter 'X' only in the second textbox and click 'send' The result is shown as "x = , y=" which should actually be "x = , y = X" The following change fixes the issue: --- a/src/Manos/Manos.Http/HttpFormDataHandler.cs +++ b/src/Manos/Manos.Http/HttpFormDataHandler.cs @@ -88,8 +88,6 @@ namespace Manos.Http { ``` private void FinishPair (HttpEntity entity) { ``` - if (value_buffer.Length == 0) - return;
atsushieno commented 13 years ago

Ugh, the repro code sanitizer swallowed almost entire report :( Let me repeat it:

manos does not handle form entries when there is an empty input text.

Repro:

1) manos -init foobar 2) Add the following methods in foobar.cs

            [Route ("/")]
            public void Index (IManosContext ctx)
            {
                    ctx.Response.End ("<html><body><form action='/a' method='POST'>  <input type='text' name='x' />  <input type='text' name='y' />  <input type='submit' value='send' />  </body></html>");
            }

            [Route ("/a")]
            public void ProcessPost (IManosContext ctx)
            {
                    ctx.Response.End ("x = {0}, y = {1}",
                            ctx.Request.Data ["x"],
                            ctx.Request.Data ["y"]);
            }

3) run manos -build and manos -server 4) go to http://localhost:8080 5) Enter '1' only in the second textbox and click "send"

It prints "x = , y = " which should actually be "x = , y = 1"

The following change fixes the issue:

--- a/src/Manos/Manos.Http/HttpFormDataHandler.cs
+++ b/src/Manos/Manos.Http/HttpFormDataHandler.cs
@@ -88,8 +88,6 @@ namespace Manos.Http {

                private void FinishPair (HttpEntity entity)
                {
-                       if (value_buffer.Length == 0)
-                               return;
jacksonh commented 13 years ago

Fixed, thanks.