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

Blank space on the end of Content-disposition #10

Closed
m1dok opened this issue Jun 6, 2023 · 0 comments
Closed

Blank space on the end of Content-disposition #10

m1dok opened this issue Jun 6, 2023 · 0 comments

Comments

@m1dok
Copy link
Contributor

m1dok commented Jun 6, 2023

If I set a blank space on the end of content-Disposition header in multipart/form-data, serverino throws a
core.exception.ArrayIndexError.

In line 521 of interfaces, the .strip method is used without checking that the array is empty.

auto k = f[0].strip; auto v = f[1].strip;

I modified a previous test to reproduce the error, just add the following test:


   //Blank space on Content-Disposition in multipart/form-data
  
      {
      string content;
      string postBody =
"-----------------------------blahblahblah\r
Content-Disposition: form-data; name=\"field1\"\r
\r
first value\r
-----------------------------blahblahblah\r
Content-Disposition: form-data; name=\"field2\"\r
\r
second value\r
-----------------------------blahblahblah\r
Content-Disposition: form-data; name=\"myfile\"; filename=\"file1.txt\";\"   \"\r
Content-Type: application/json     \r
\r
{}
\r
-----------------------------blahblahblah--\r
";

      auto http = HTTP("http://myuser@127.0.0.1:8080/json/dump/test?");
      http.setPostData(postBody,"multipart/form-data; boundary=---------------------------blahblahblah");
      http.method = HTTP.Method.post;
      http.onReceive = (ubyte[] data) { content ~= data; return data.length; };
      http.perform();

      auto j = parseJSON(content);

      assert(j["method"].str == "POST");
      assert(j["uri"].str == "/json/dump/test");
      assert(j["host"].str == "127.0.0.1:8080");

      assert(j["get"].array.map!(x=>x.str).array.sort.array == []);
      assert(j["post"].array.map!(x=>x.str).array.sort.array == []);
      assert(j["cookie"].array.map!(x=>x.str).array.sort.array == []);

      assert(j["username"].str == "myuser");
      assert(j["password"].str == string.init);

      assert(j["form-data"].array.map!(x=>x.str).array.sort.array == ["field1,text/plain,first value", "field2,text/plain,second value"]);
      assert(j["form-file"].array.map!(x=>x.str).array.sort.array == ["myfile,file1.txt,application/json,{}\n"]);

      assert(j["content-type"].str == "multipart/form-data");
   }
@m1dok m1dok mentioned this issue Jun 6, 2023
trikko added a commit that referenced this issue Jun 6, 2023
@trikko trikko closed this as completed Jun 6, 2023
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

No branches or pull requests

2 participants