kazeburo / Kossy

sinatra-ish simple waf
Other
35 stars 13 forks source link

Fixed JSON request had 1 or 0 array elements and add json_parameters method #21

Closed kfly8 closed 10 months ago

kfly8 commented 10 months ago

This pull request solves the following problems.

Problem

When requesting JSON with one or zero array elements, the body parameters are no longer an array:

Case: POST { b => [123] }
Then: { b => 123} 
Expected body parameters : { b => [123] }

Case: POST { b => [] }
Then: {} 
Expected body parameters : { b => [] }

The following test code reproduces this problem. t/100_bugs/002_a_few_parameters_in_json_body.t

Solutions

  1. Decode body parameters recursively.
  2. Added json_parameters method for easier handling of JSON requests.