# `Macaw.Layers.Untrusted`
[🔗](https://github.com/dcoai/macaw_layers/blob/v0.4.0/lib/macaw/layers/untrusted.ex#L1)

The checks for untrusted text (spec/01 §8): a string a document holds that is written
into CSS, SVG or a page holds only what its context can carry. Each document type says
which of its strings these are, and judges them with these checks, so every type refuses
the same strings as `{:unsafe, kind}` at their path.

    iex> Macaw.Layers.Untrusted.font_family?("Inter, 'Segoe UI', sans-serif")
    true
    iex> Macaw.Layers.Untrusted.font_family?("x; } body { color: red")
    false
    iex> Macaw.Layers.Untrusted.class?("critical wide")
    true
    iex> Macaw.Layers.Untrusted.identifier?("6x")
    false

Ported from visualize's validator (its spec/14 §10.3).

# `check`

```elixir
@spec check(:font_family | :class | :identifier, term(), Macaw.Layers.Fault.path()) ::
  [
    Macaw.Layers.Fault.t()
  ]
```

The fault for a string at `path` that the check of `kind` refuses, or none:
`[{path, {:unsafe, kind}}]` or `[]`. `kind` is `:font_family`, `:class` or `:identifier`.

    iex> Macaw.Layers.Untrusted.check(:class, "a\" onload=\"x", [:styles, "s", :class])
    [{[:styles, "s", :class], {:unsafe, :class}}]

# `class?`

```elixir
@spec class?(term()) :: boolean()
```

Whether a string is one or more CSS class names separated by spaces, each
`-?[_a-zA-Z][_a-zA-Z0-9-]*`.

# `font_family?`

```elixir
@spec font_family?(term()) :: boolean()
```

Whether a string is a font family list: no `<`, `>`, `/`, `;`, `{`, `}`, `\` or control
character, and every quote closed. Commas, spaces and quotes stay, since a family list
is `Inter, 'Segoe UI', sans-serif`; an unclosed quote would run past its declaration.

# `identifier?`

```elixir
@spec identifier?(term()) :: boolean()
```

Whether a string is one CSS identifier, `-?[_a-zA-Z][_a-zA-Z0-9-]*`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
