Skip to content

Commit

Permalink
Fix off-by-one in tootctl media commands (mastodon#30306)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and ttrace committed Jul 5, 2024
1 parent 73f036d commit 6909b18
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/mastodon/cli/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def remove_orphans

model_name = path_segments.first.classify
attachment_name = path_segments[1].singularize
record_id = path_segments[2..-2].join.to_i
record_id = path_segments[2...-2].join.to_i
file_name = path_segments.last
record = record_map.dig(model_name, record_id)
attachment = record&.public_send(attachment_name)
Expand Down Expand Up @@ -180,7 +180,7 @@ def remove_orphans
end

model_name = path_segments.first.classify
record_id = path_segments[2..-2].join.to_i
record_id = path_segments[2...-2].join.to_i
attachment_name = path_segments[1].singularize
file_name = path_segments.last

Expand Down Expand Up @@ -311,7 +311,7 @@ def lookup(url)
end

model_name = path_segments.first.classify
record_id = path_segments[2..-2].join.to_i
record_id = path_segments[2...-2].join.to_i

unless PRELOAD_MODEL_WHITELIST.include?(model_name)
say("Cannot find corresponding model: #{model_name}", :red)
Expand Down Expand Up @@ -361,7 +361,7 @@ def preload_records_from_mixed_objects(objects)
next unless VALID_PATH_SEGMENTS_SIZE.include?(segments.size)

model_name = segments.first.classify
record_id = segments[2..-2].join.to_i
record_id = segments[2...-2].join.to_i

next unless PRELOAD_MODEL_WHITELIST.include?(model_name)

Expand Down

0 comments on commit 6909b18

Please sign in to comment.