From a6678f66226b2644c6d9961bdeed761aac3eeab3 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Fri, 12 Aug 2016 21:17:57 +0200 Subject: [PATCH] Use String#starts_with? instead of String#[]? (#194) It shows real intention and covers cases when `application/json` is passed in the middle of the string, like `some_garbage_string; application/json` --- src/kemal/param_parser.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kemal/param_parser.cr b/src/kemal/param_parser.cr index d1e5464..db54bad 100644 --- a/src/kemal/param_parser.cr +++ b/src/kemal/param_parser.cr @@ -55,7 +55,7 @@ module Kemal # If request body is a JSON Array it's added into `params` as `_json` and can be accessed # like params["_json"] def parse_json - return unless @request.body && @request.headers["Content-Type"]?.try(&.[APPLICATION_JSON]?) + return unless @request.body && @request.headers["Content-Type"]?.try(&.starts_with?(APPLICATION_JSON)) body = @request.body.as(String) case json = JSON.parse(body).raw