isSafeHeredoc function

bool isSafeHeredoc(
  1. String command
)

Check if a heredoc is safe (delimiter is quoted/escaped).

Implementation

bool isSafeHeredoc(String command) {
  final heredocMatch = RegExp(r'<<-?\s*(\S+)').firstMatch(command);
  if (heredocMatch == null) return true;

  final delimiter = heredocMatch.group(1)!;

  // Quoted delimiter is safe
  if (delimiter.startsWith("'") || delimiter.startsWith('"')) return true;

  // Escaped delimiter is safe
  if (delimiter.startsWith(r'\')) return true;

  // Unquoted delimiter allows variable substitution — potentially unsafe
  return false;
}