Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@ exports.wrapSequelize = (sequelize) => {
// Allow only alphanumeric, periods, slashes, dashes, underscores,
// spaces, newlines. The main concern is preventing injection of '*/
// within the stacktrace.
const commentStr = `stacktrace='${makeMinimalUsefulStacktrace().replace(/[^\w.:/\\\-\s\n]/g, '')}'`;
//
// We also don't include any quotes with the stacktrace because
// mysqldumpslow (which aggregates slow query logs) by default replaces
// all strings with quotes with 'S'. We don't want that, since we want
// to see stacktraces in our slow query logs.
const commentStr = `stacktrace=\n${makeMinimalUsefulStacktrace().replace(/[^\w.:/\\\-\s\n]/g, '')}`;

if (commentStr && commentStr.length > 0)
sql = `${sql} /*${commentStr}*/`;
sql = `${sql} /* ${commentStr} */`;

return run.apply(this, [sql, sql_options]);
};

// Finally mark the object as having already been wrapped.
sequelize.___alreadySQLCommenterWrapped___ = true;
}
}
13 changes: 8 additions & 5 deletions test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ describe("Unit", () => {
});
});

describe("makeMinimalUsefulStacktrace", () => {
it("should only contain about 4 lines of context", () => {
expect(makeMinimalUsefulStacktrace().match(/\n/g) || []).to.have.length(3);
});
});
// This test doesn't work well since when we run the test with mocha, the
// test functions in node_modules are at the bottom, resulting in us
// getting the wrong stacktrace
// describe("makeMinimalUsefulStacktrace", () => {
// it("should only contain about 4 lines of context", () => {
// expect(makeMinimalUsefulStacktrace().match(/\n/g) || []).to.have.length(3);
// });
// });
});
2 changes: 1 addition & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ exports.makeMinimalUsefulStacktrace = () => {
.join('\n');

return minimalUsefulStacktrace;
}
}