Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about sed pattern variable expansion with unescaped forward shashes #1623

Open
karolinepauls opened this issue Jun 26, 2019 · 0 comments

Comments

@karolinepauls
Copy link

For new checks and feature suggestions

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

#!/bin/bash
AAA='AAA/AAA'
sed "s/12/$AAA/"

Here's what shellcheck currently says:

No issues detected!

Here's what I wanted or expected to see:

Line 3:
sed "s/12/$AAA/"
^-- SCXXXX: Variable expansion in sed patterns should escape forward slashes, like: "${VARIABLE//\//\\/}"; ignore if variable is already escaped.

Not all shells can use character substitution when expanding variables.

It may be hard to detect if forward slashes are escaped correctly but it's easy to detect they're not escaped at all.

False positives: without the "ignore if variable is already escaped" clause, if the string is already escaped, we risk suggesting to double-escape it. However, if it contains no slashes, escaping them won't change anything.

There may be better ways to escape forward slashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant