diff --git a/README.md b/README.md index 79309b1f..50e1f35e 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ | Python | Flask | ✅ | X | X | X | X | | Ruby | Rails | ✅ | ✅ | ✅ | ✅ | X | | Ruby | Sinatra | ✅ | ✅ | ✅ | ✅ | X | -| Php | | ✅ | ✅ | ✅ | X | X | +| Php | | ✅ | ✅ | ✅ | ✅ | X | | Java | Spring | ✅ | ✅ | X | X | X | | Java | Jsp | X | X | X | X | X | | Crystal | Kemal | ✅ | ✅ | ✅ | ✅ | ✅ | diff --git a/shard.yml b/shard.yml index 95eff65d..42dcda32 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: noir -version: 0.5.2 +version: 0.5.4 authors: - hahwul diff --git a/spec/functional_test/fixtures/php_pure/post.php b/spec/functional_test/fixtures/php_pure/post.php index d3182423..79b63448 100644 --- a/spec/functional_test/fixtures/php_pure/post.php +++ b/spec/functional_test/fixtures/php_pure/post.php @@ -1,3 +1,4 @@ \ No newline at end of file diff --git a/spec/functional_test/testers/php_pure_spec.cr b/spec/functional_test/testers/php_pure_spec.cr index 44c591db..e1da60e8 100644 --- a/spec/functional_test/testers/php_pure_spec.cr +++ b/spec/functional_test/testers/php_pure_spec.cr @@ -7,7 +7,10 @@ extected_endpoints = [ Param.new("param1", "", "query"), ]), Endpoint.new("/post.php", "GET"), - Endpoint.new("/post.php", "POST", [Param.new("param1", "", "form")]), + Endpoint.new("/post.php", "POST", [ + Param.new("param1", "", "form"), + Param.new("password", "", "form"), + ]), Endpoint.new("/request.php", "GET", [Param.new("param1", "", "query")]), Endpoint.new("/request.php", "POST", [Param.new("param1", "", "form")]), ] diff --git a/src/analyzer/analyzers/analyzer_php_pure.cr b/src/analyzer/analyzers/analyzer_php_pure.cr index 894001e3..89420cbe 100644 --- a/src/analyzer/analyzers/analyzer_php_pure.cr +++ b/src/analyzer/analyzers/analyzer_php_pure.cr @@ -20,26 +20,28 @@ class AnalyzerPhpPure < Analyzer methods = [] of String file.each_line do |line| - match = line.strip.match(%r{.*\$_(.*?)\['(.*?)'\];}) + if allow_patterns.any? { |pattern| line.includes? pattern } + match = line.strip.match(/\$_(.*?)\['(.*?)'\]/) - if match - method = match[1] - param_name = match[2] + if match + method = match[1] + param_name = match[2] - if method == "GET" - params_query << Param.new(param_name, "", "query") - elsif method == "POST" - params_body << Param.new(param_name, "", "form") - methods << "POST" - elsif method == "REQUEST" - params_query << Param.new(param_name, "", "query") - params_body << Param.new(param_name, "", "form") - methods << "POST" - elsif method == "SERVER" - if param_name.includes? "HTTP_" - param_name = param_name.sub("HTTP_", "").gsub("_", "-") - params_query << Param.new(param_name, "", "header") - params_body << Param.new(param_name, "", "header") + if method == "GET" + params_query << Param.new(param_name, "", "query") + elsif method == "POST" + params_body << Param.new(param_name, "", "form") + methods << "POST" + elsif method == "REQUEST" + params_query << Param.new(param_name, "", "query") + params_body << Param.new(param_name, "", "form") + methods << "POST" + elsif method == "SERVER" + if param_name.includes? "HTTP_" + param_name = param_name.sub("HTTP_", "").gsub("_", "-") + params_query << Param.new(param_name, "", "header") + params_body << Param.new(param_name, "", "header") + end end end end @@ -58,8 +60,8 @@ class AnalyzerPhpPure < Analyzer result end - def allow_methods - ["GET", "POST", "PUT", "DELETE", "PATCH"] + def allow_patterns + ["$_GET", "$_POST", "$_REQUEST", "$_SERVER"] end end diff --git a/src/models/noir.cr b/src/models/noir.cr index ae770302..28373140 100644 --- a/src/models/noir.cr +++ b/src/models/noir.cr @@ -127,7 +127,7 @@ class NoirRunner if param.param_type == "form" if first_form final_body += "#{param.name}=#{param.value}" - first_form + first_form = false else final_body += "&#{param.name}=#{param.value}" end diff --git a/src/noir.cr b/src/noir.cr index eea4bc7c..1d2ddd68 100644 --- a/src/noir.cr +++ b/src/noir.cr @@ -6,7 +6,7 @@ require "./options.cr" require "./techs/techs.cr" module Noir - VERSION = "0.5.2" + VERSION = "0.5.4" end noir_options = default_options()