Skip to content

Commit c046f5d

Browse files
Copilothahwul
andauthored
chore: dedupe yesod route normalization
Agent-Logs-Url: https://github.com/owasp-noir/noir/sessions/9fd8b4a3-f603-444b-bed9-1cd440060a77 Co-authored-by: hahwul <13212227+hahwul@users.noreply.github.com>
1 parent cf4d61b commit c046f5d

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/analyzer/analyzers/haskell/yesod.cr

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,13 @@ module Analyzer::Haskell
232232

233233
private def extract_raw_segments(pattern : String) : Array(String)
234234
normalized = pattern
235-
normalized = normalized[1..] if normalized.starts_with?("!")
236-
normalized = normalized[1..] if normalized.starts_with?("/")
235+
while normalized.starts_with?("!") || normalized.starts_with?("/")
236+
normalized = normalized[1..]
237+
end
237238

238239
return [] of String if normalized.empty?
239240

240-
normalized.split('/').reject(&.empty?)
241+
normalized.split('/').reject(&.empty?).map { |segment| strip_overlap_markers(segment) }
241242
end
242243

243244
private def build_url_and_params(raw_segments : Array(String)) : Tuple(String, Array(Param))
@@ -246,7 +247,7 @@ module Analyzer::Haskell
246247
name_counts = Hash(String, Int32).new(0)
247248

248249
raw_segments.each do |raw_segment|
249-
segment = raw_segment.gsub("!", "")
250+
segment = raw_segment
250251

251252
if segment.starts_with?("#")
252253
type_name = segment[1..]
@@ -267,6 +268,10 @@ module Analyzer::Haskell
267268
{url, params}
268269
end
269270

271+
private def strip_overlap_markers(segment : String) : String
272+
segment.gsub("!", "")
273+
end
274+
270275
private def next_param_name(type_name : String, name_counts : Hash(String, Int32)) : String
271276
base_name = sanitize_param_name(type_name)
272277
current_count = name_counts[base_name]? || 0

0 commit comments

Comments
 (0)