Updated SC2140 (markdown)

koalaman
2015-08-02 19:55:29 -07:00
parent c6adf2a0e0
commit 11be176dc9

@@ -1,24 +1,48 @@
## The double quotes around this do nothing. Remove or escape them. ## Word is on the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?
### Problematic code: ### Problematic code:
echo "<img src="foo.png" />" > file.html echo "<img src="foo.png" />" > file.html
or
export "var"="42"
### Correct code: ### Correct code:
echo "<img src=\"foo.png\" />" > file.html echo "<img src=\"foo.png\" />" > file.html
or
export "var=42"
### Rationale: ### Rationale:
This warning triggers when an unquoted literal string is found between two double quoted strings. In many such cases (like the example) the quotes were supposed to be literal, and should be escaped. Without escaping, the quotes are simply removed, resulting in `src=foo.png` instead of `src="foo.png"`. This warning triggers when an unquoted literal string is found suspiciously sandwiched between two double quoted strings.
It's common not to realize that double quotes can span multiple elements. For example, the following strings are identical: This usually indicates one of:
http://"$user":"$password"@"$host"/"$path" - quotes that were supposed to be nested, and therefore need to be escaped (like the `<img>` example)
"http://$user:$password@$host/$path" - quotes that are just plain unnecessary (like the `export` example).
When ShellCheck detects the former style (i.e. the double quotes include only a single element each), it will suppress the warning. Without escaping, the inner two quotes of the sandwich (the end quote of the first section and the start quote of the second section) are no-ops. The following two statements are identical, so the quotes that were intended to be part of the html output are instead removed:
echo "<img src="foo.png" />" > file.html
echo "<img src=foo.png />" > file.html
Similarly, these statements are identical, but work as intended:
export "var"="42"
export "var=42"
### Exceptions ### Exceptions
If you know that the quotes are ineffectual but you prefer it stylistically, you can ignore this message. If you know that the quotes are ineffectual but you prefer it stylistically, you can ignore this message.
It's common not to realize that double quotes can span multiple elements, or to stylistically prefer to quote individual variables. For example, these statements are identical, but the first is laboriously and redundantly quoted:
http://"$user":"$password"@"$host"/"$path"
"http://$user:$password@$host/$path"
When ShellCheck detects the first style (i.e. the double quotes include only a single element each), it will suppress the warning.