#1159 asked for the possibility for more custom behavior when failing validations of UTF-8 strings. This PR adds a new function Plug.Conn.Utils.validate_utf8/3 as an alternative to Plug.Conn.Utils.validate_utf8!/3. The new function has a parameter for a function on how to handle a failure (with the error message supplied as input to the function).
The changes are backward compatible, but updating Plug.Conn.Query to use the new function makes the signature of Plug.Conn.Query.decode/5 a bit verbose and clunky. When the try-rescue will be removed from Plug.Conn.Query.decode_www_pair/4, there will no longer be any need for both a parameter for an exception and a function, but it would be a breaking change in the future to remove the exception parameter in favor of only the function.
#1159 asked for the possibility for more custom behavior when failing validations of UTF-8 strings. This PR adds a new function Plug.Conn.Utils.validate_utf8/3 as an alternative to Plug.Conn.Utils.validate_utf8!/3. The new function has a parameter for a function on how to handle a failure (with the error message supplied as input to the function). The changes are backward compatible, but updating Plug.Conn.Query to use the new function makes the signature of Plug.Conn.Query.decode/5 a bit verbose and clunky. When the try-rescue will be removed from Plug.Conn.Query.decode_www_pair/4, there will no longer be any need for both a parameter for an exception and a function, but it would be a breaking change in the future to remove the exception parameter in favor of only the function.