Skip to content

[SC3057] False positive with multiline variable expressions #3394

@eehakkin

Description

@eehakkin

For bugs with existing features

Here's a snippet or screenshot that shows the problem:

#! /bin/sh
cat << __LDIF__
dn: ${dn?}
changetype: modify${cn:+
replace: cn
cn: ${cn}
-}${uid:+
replace: uid
uid: ${uid}
-}

__LDIF__

Here's what shellcheck currently says:

[Line 4:](javascript:setPosition(4, 19))
changetype: modify${cn:+
                  ^-- [SC3057](https://www.shellcheck.net/wiki/SC3057) (warning): In POSIX sh, string indexing is undefined.
 
[Line 7:](javascript:setPosition(7, 3))
-}${uid:+
  ^-- [SC3057](https://www.shellcheck.net/wiki/SC3057) (warning): In POSIX sh, string indexing is undefined.

Here's what I wanted or expected to see:

Nothing. The code does not use string indexing.

More info

src/ShellCheck/Checks/ShellSupport.hs has simpleExpansions which makes a regular expression ^[_0-9a-zA-Z*@]+:[^-=?+] which can match not only in the beginning of a dollar brace expression but also in the beginning of lines within the dollar brace expression. It thus gives false positives for cn: , replace: and uid: even though those are not variable expressions at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions