Skip to content

Commit

Permalink
String match bug cause 'href' can be a list. (#2389)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshull authored Feb 19, 2025
1 parent cb0b0f7 commit 7775495
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/dotcom/content_rewriters/links.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ defmodule Dotcom.ContentRewriters.Links do
"""
def add_locale_params({"a", attrs, children} = element, %{cookies: %{"googtrans" => languages}}) do
attr_map = Enum.into(attrs, %{})
href = Map.get(attr_map, "href", "")
locale = String.split(languages, "/") |> List.last()

href =
case Map.get(attr_map, "href") do
href when is_binary(href) -> href
[href] -> href
_ -> ""
end

if String.match?(href, ~r/mycharlie.mbta.com/) do
updated_href = "#{href}?locale=#{locale}"
updated_attrs = attr_map |> Map.replace!("href", updated_href) |> Map.to_list()
Expand Down

0 comments on commit 7775495

Please sign in to comment.