Unquoted tr Arguments Medium

Unquoted arguments to the 'tr' command can lead to unexpected glob expansion by the shell. To prevent this, enclose the 'tr' arguments in single quotes.

Detector ID
shell/unquoted-tr-arguments@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-
Tags
-

Noncompliant example

1
2# Noncompliant: Unquoted `tr` parameters can lead to unintended glob expansion.
3echo "Hello, World!" | tr [:lower:] [:upper:]

Compliant example

1
2# Compliant: Quoted `tr` parameters prevent glob expansion, ensuring correct character class usage.
3echo "Hello, World!" | tr '[:lower:]' '[:upper:]'