Current section
Files
Jump to
Current section
Files
lib/relyra/security/xml/attribute_escape.ex
defmodule Relyra.Security.XML.AttributeEscape do
@moduledoc """
Escapes a string for use in an XML attribute value per Exclusive C14N rules.
Mirrors the replacements in `Relyra.Security.XML.C14n` private `escape_attr/1`
without coupling callers to C14n internals.
"""
@spec escape_attribute(term()) :: binary()
def escape_attribute(value) when is_binary(value) do
value
|> :binary.replace("&", "&", [:global])
|> :binary.replace("<", "<", [:global])
|> :binary.replace("\"", """, [:global])
|> :binary.replace("\t", "	", [:global])
|> :binary.replace("\n", "
", [:global])
|> :binary.replace("\r", "
", [:global])
end
def escape_attribute(_), do: ""
end