Skip to content

bug: $'\\n' not expanded when concatenated in function argument position #862

@chaliy

Description

@chaliy

Problem

When $'\n' (ANSI-C quoting) is concatenated with adjacent double-quoted strings and passed directly as a function argument, the $'\n' is not expanded — it becomes the literal characters $\n.

This works correctly in variable assignment but fails in function call argument position.

Reproduction

show() { printf 'arg: %q\n' "$1"; }

# BROKEN: direct function argument
show "line1"$'\n'"line2"
# Expected: $'line1\nline2'
# Actual:   line1\$\\nline2  (literal $\n)

# WORKS: via variable
x="line1"$'\n'"line2"
show "${x}"
# Expected: $'line1\nline2'  ✓

Impact

Medium — any code that passes concatenated ANSI-C quoted strings directly as function arguments gets literal $\n instead of a newline. Common workaround: assign to a variable first.

Used in wedow/harness message assembly where body content is built with $'\n' concatenation.

Test cases

show() { printf '%q\n' "$1"; }

# $'\n' between double-quoted strings as argument
show "a"$'\n'"b"
# Expected: $'a\nb'

# $'\t' between double-quoted strings as argument
show "a"$'\t'"b"
# Expected: $'a\tb'

# $'\n' as sole argument
show $'\n'
# Expected: $'\n'

# $'\n' at start
show $'\n'"after"
# Expected: $'\nafter'

# $'\n' at end
show "before"$'\n'
# Expected: $'before\n'

# Multiple ANSI-C segments
show "a"$'\n'"b"$'\t'"c"
# Expected: $'a\nb\tc'

# Works in assignment (baseline)
x="a"$'\n'"b"
show "${x}"
# Expected: $'a\nb'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions