ExMCP.Internal.AtomUtils (ex_mcp v1.0.0-rc.0)

View Source

Internal utilities for safe atom handling.

This module provides functions to safely convert strings to atoms without risking atom table exhaustion from untrusted input.

Summary

Functions

Safely converts a binary string to an atom if the atom already exists. Otherwise, returns a generic :unknown_key atom. Prevents atom exhaustion attacks and ensures consistent map key types.

Functions

safe_string_to_atom(key)

@spec safe_string_to_atom(String.t() | atom()) :: atom()

Safely converts a binary string to an atom if the atom already exists. Otherwise, returns a generic :unknown_key atom. Prevents atom exhaustion attacks and ensures consistent map key types.

Examples

iex> ExMCP.Internal.AtomUtils.safe_string_to_atom("name")
:name  # if :name already exists

iex> ExMCP.Internal.AtomUtils.safe_string_to_atom("unknown_key_12345")
:__unknown_key__  # returns generic atom for unknown keys