@@ -176,32 +176,27 @@ defmodule Phoenix.HTML.Link do
176
176
{ value , opts }
177
177
end
178
178
179
- defp valid_destination! ( to , calling_func ) do
180
- if invalid_destination? ( to ) do
181
- raise ArgumentError , """
182
- unsupported scheme given to #{ calling_func } . In case you want to link to an
183
- unknown or unsafe scheme, such as javascript, use a tuple: {:javascript, rest}
184
- """
185
- end
186
-
187
- valid_destination! ( to )
188
- end
189
- defp valid_destination! ( { :safe , to } ) do
190
- { :safe , valid_destination! ( to ) }
179
+ defp valid_destination! ( { :safe , to } , context ) do
180
+ { :safe , valid_string_destination! ( IO . iodata_to_binary ( to ) , context ) }
191
181
end
192
- defp valid_destination! ( { other , to } ) when is_atom ( other ) do
182
+ defp valid_destination! ( { other , to } , _context ) when is_atom ( other ) do
193
183
[ Atom . to_string ( other ) , ?: , to ]
194
184
end
195
- defp valid_destination! ( to ) , do: to
185
+ defp valid_destination! ( to , context ) do
186
+ valid_string_destination! ( IO . iodata_to_binary ( to ) , context )
187
+ end
196
188
197
189
for scheme <- @ valid_uri_schemes do
198
- defp invalid_destination? ( unquote ( scheme ) <> _ ) , do: false
190
+ defp valid_string_destination! ( unquote ( scheme ) <> _ = string , _context ) , do: string
199
191
end
200
- defp invalid_destination? ( { scheme , _ } ) when is_atom ( scheme ) do
201
- false
202
- end
203
- defp invalid_destination? ( to ) when is_binary ( to ) do
204
- String . contains? ( to , ":" )
192
+ defp valid_string_destination! ( to , context ) do
193
+ if String . contains? ( to , ":" ) do
194
+ raise ArgumentError , """
195
+ unsupported scheme given to #{ context } . In case you want to link to an
196
+ unknown or unsafe scheme, such as javascript, use a tuple: {:javascript, rest}
197
+ """
198
+ else
199
+ to
200
+ end
205
201
end
206
- defp invalid_destination? ( _ ) , do: true
207
202
end
0 commit comments