Skip to content

Commit

Permalink
Track visited URL paths to prevent duplicate processing in Django end…
Browse files Browse the repository at this point in the history
…point extraction

ref: #428

Signed-off-by: ksg <ksg97031@gmail.com>
  • Loading branch information
ksg97031 committed Nov 6, 2024
1 parent 2cb21b6 commit 8a1d92d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/analyzer/analyzers/python/django.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Analyzer::Python
class Django < Python
# Base path for the Django project
@django_base_path : ::String = ""
@visited_url_paths = Hash(String, Bool).new

# Regular expressions for extracting Django URL configurations
REGEX_ROOT_URLCONF = /\s*ROOT_URLCONF\s*=\s*r?['"]([^'"\\]*)['"]/
Expand Down Expand Up @@ -98,6 +99,7 @@ module Analyzer::Python
logger.debug "Extracting endpoints from #{django_urls.filepath}"
endpoints = [] of Endpoint
url_base_path = File.dirname(django_urls.filepath)
@visited_url_paths[django_urls.filepath] = true

file = File.open(django_urls.filepath, encoding: "utf-8", invalid: :skip)
content = file.gets_to_end
Expand Down Expand Up @@ -129,7 +131,7 @@ module Analyzer::Python
if File.exists?(new_route_path)
new_django_urls = DjangoUrls.new("#{django_urls.prefix}#{route}", new_route_path, django_urls.basepath)
details = Details.new(PathInfo.new(new_route_path))
if new_django_urls.filepath != django_urls.filepath
unless @visited_url_paths.has_key? new_django_urls.filepath
extract_endpoints(new_django_urls).each do |endpoint|
endpoint.details = details
endpoints << endpoint
Expand All @@ -143,6 +145,7 @@ module Analyzer::Python
if view == ""
endpoints << Endpoint.new(url, "GET", details)
else
next if view.includes? "(" # unsupported pattern
dotted_as_names_split = view.split(".")

filepath = ""
Expand Down

0 comments on commit 8a1d92d

Please sign in to comment.