Skip to content

Commit d7f86db

Browse files
committed
Enhance PipeCall to exclude non-function and non-object arguments in pipe method detection
1 parent 4332de4 commit d7f86db

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

javascript/ql/src/Quality/UnhandledStreamPipe.ql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import javascript
1515
* A call to the `pipe` method on a Node.js stream.
1616
*/
1717
class PipeCall extends DataFlow::MethodCallNode {
18-
PipeCall() { this.getMethodName() = "pipe" and this.getNumArgument() = [1, 2] }
18+
PipeCall() {
19+
this.getMethodName() = "pipe" and
20+
this.getNumArgument() = [1, 2] and
21+
not this.getArgument(0).asExpr() instanceof Function and
22+
not this.getArgument(0).asExpr() instanceof ObjectExpr
23+
}
1924

2025
/** Gets the source stream (receiver of the pipe call). */
2126
DataFlow::Node getSourceStream() { result = this.getReceiver() }

javascript/ql/test/query-tests/Quality/UnhandledStreamPipe/test.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@
1515
| test.js:185:5:185:32 | copyStr ... nation) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
1616
| test.js:190:17:190:40 | notStre ... itable) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
1717
| test.js:195:17:195:40 | notStre ... itable) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
18-
| test.js:199:5:199:22 | notStream.pipe({}) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
19-
| test.js:203:5:203:26 | notStre ... ()=>{}) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
2018
| test.js:207:5:207:64 | getStre ... e(dest) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
2119
| test.js:212:5:212:56 | getStre ... e(dest) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |

javascript/ql/test/query-tests/Quality/UnhandledStreamPipe/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ function test() {
196196
}
197197
{
198198
const notStream = getNotAStream();
199-
notStream.pipe({}); // $SPURIOUS:Alert
199+
notStream.pipe({});
200200
}
201201
{
202202
const notStream = getNotAStream();
203-
notStream.pipe(()=>{}); // $SPURIOUS:Alert
203+
notStream.pipe(()=>{});
204204
}
205205
{
206206
const plumber = require('gulp-plumber');

0 commit comments

Comments
 (0)