Skip to content

Commit b39a884

Browse files
committed
fix: solve RIOT ID string parsing
1 parent ca66a9e commit b39a884

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

app/modules/players/services/riot_sync_service.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,10 @@ def search_riot_id(game_name, tag_line)
237237
Rails.logger.info("Regional endpoint: #{regional_endpoint}")
238238

239239
# Use whitelisted host to prevent SSRF
240-
# Use ERB::Util.url_encode instead of CGI.escape to properly encode spaces as %20 (not +)
241-
encoded_game_name = ERB::Util.url_encode(game_name)
242-
encoded_tag_line = ERB::Util.url_encode(tag_line)
240+
# CGI.escape encodes spaces as '+', which is only valid in query strings, not path segments.
241+
# Riot API path params require '%20' for spaces, so we replace '+' after escaping.
242+
encoded_game_name = CGI.escape(game_name).gsub('+', '%20')
243+
encoded_tag_line = CGI.escape(tag_line).gsub('+', '%20')
243244

244245
Rails.logger.info("Encoded game_name: '#{game_name}' -> '#{encoded_game_name}'")
245246
Rails.logger.info("Encoded tag_line: '#{tag_line}' -> '#{encoded_tag_line}'")

app/modules/scrims/controllers/lobby_controller.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LobbyController < Api::V1::BaseController
1717
def index
1818
scrims = Scrim.unscoped
1919
.eager_load(:organization)
20-
.includes(:opponent_team)
20+
.includes(:opponent_team, organization: :players)
2121
.where(scrims: { visibility: 'public' })
2222
.where(organizations: { is_public: true })
2323
.where('scrims.scheduled_at >= ?', Time.current)
@@ -69,10 +69,28 @@ def serialize_lobby_scrim(scrim)
6969
region: org.region,
7070
tier: org.try(:tier),
7171
public_tagline: org.try(:public_tagline),
72-
discord_invite_url: org.try(:discord_invite_url)
72+
discord_invite_url: org.try(:discord_invite_url),
73+
roster: serialize_org_roster(org)
7374
}
7475
}
7576
end
77+
78+
# Returns the org's active players sorted by role, already preloaded via includes.
79+
# Capped at 10 to keep the response lean.
80+
def serialize_org_roster(org)
81+
role_sort = %w[top jungle mid adc support]
82+
players = org.players.select(&:active?)
83+
players.sort_by { |p| [role_sort.index(p.role) || 99, p.summoner_name] }
84+
.first(10)
85+
.map do |p|
86+
{
87+
summoner_name: p.summoner_name,
88+
role: p.role,
89+
tier: p.solo_queue_tier,
90+
tier_rank: p.solo_queue_rank
91+
}
92+
end
93+
end
7694
end
7795
end
7896
end

0 commit comments

Comments
 (0)