Skip to content

Standardize file extension checks across detectors #503

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

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/detector/detectors/javascript/express.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "../../../models/detector"
module Detector::Javascript
class Express < Detector
def detect(filename : String, file_contents : String) : Bool
if (filename.includes?(".js") || filename.includes?(".mjs") || filename.includes?(".ts")) &&
if (filename.ends_with?(".js") || filename.ends_with?(".mjs") || filename.ends_with?(".ts")) &&
(file_contents.match(/require\(['"]express['"]\)/) ||
file_contents.match(/import express from ['"]express['"]/) ||
file_contents.match(/import { Router } from ['"]express['"]/) ||
Expand Down
6 changes: 3 additions & 3 deletions src/detector/detectors/javascript/restify.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ require "../../../models/detector"
module Detector::Javascript
class Restify < Detector
def detect(filename : String, file_contents : String) : Bool
if (filename.includes? ".js") && (file_contents.includes? "require('restify')")
if (filename.ends_with? ".js") && (file_contents.includes? "require('restify')")
true
elsif (filename.includes? ".js") && (file_contents.includes? "require(\"restify\")")
elsif (filename.ends_with? ".js") && (file_contents.includes? "require(\"restify\")")
true
elsif (filename.includes? ".ts") && (file_contents.includes? "require(\"restify\")")
elsif (filename.ends_with? ".ts") && (file_contents.includes? "require(\"restify\")")
true
else
false
Expand Down
2 changes: 1 addition & 1 deletion src/detector/detectors/php/php.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Detector::Php
def detect(filename : String, file_contents : String) : Bool
check = file_contents.includes?("<?")
check = check || file_contents.includes?("?>")
check = check && filename.includes?(".php")
check = check && filename.ends_with?(".php")

check
end
Expand Down
2 changes: 1 addition & 1 deletion src/detector/detectors/python/django.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "../../../models/detector"
module Detector::Python
class Django < Detector
def detect(filename : String, file_contents : String) : Bool
if (filename.includes? ".py") && (file_contents.includes? "from django.")
if (filename.ends_with? ".py") && (file_contents.includes? "from django.")
true
else
false
Expand Down
2 changes: 1 addition & 1 deletion src/detector/detectors/python/flask.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "../../../models/detector"
module Detector::Python
class Flask < Detector
def detect(filename : String, file_contents : String) : Bool
if (filename.includes? ".py") && (file_contents.includes? "from flask")
if (filename.ends_with? ".py") && (file_contents.includes? "from flask")
true
else
false
Expand Down
2 changes: 1 addition & 1 deletion src/detector/detectors/specification/har.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require "har"
module Detector::Specification
class Har < Detector
def detect(filename : String, file_contents : String) : Bool
if (filename.includes? ".har") || (filename.includes? ".json")
if (filename.ends_with? ".har") || (filename.ends_with? ".json")
if valid_json? file_contents
begin
data = HAR.from_string(file_contents)
Expand Down
Loading