Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Aug 8, 2020
2 parents 309eed6 + 8ba73e5 commit fb30ad5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/schema/columncompiler.js
Expand Up @@ -164,7 +164,7 @@ ColumnCompiler.prototype.defaultTo = function (value) {
) {
value = `'${JSON.stringify(value)}'`;
} else {
value = `'${value}'`;
value = this.client._escapeBinding(value.toString());
}
return `default ${value}`;
};
Expand Down
14 changes: 14 additions & 0 deletions test/unit/schema/sqlite3.js
Expand Up @@ -397,6 +397,20 @@ describe('SQLite SchemaBuilder', function () {
);
});

it('correctly escape singleQuotes passed to defaultTo()', function () {
tableSql = client
.schemaBuilder()
.table('users', function (table) {
table.string('foo').defaultTo("single 'quoted' value");
})
.toSQL();

equal(
tableSql[0].sql,
"alter table `users` add column `foo` varchar(255) default 'single ''quoted'' value'"
);
});

it('chains notNull and defaultTo', function () {
tableSql = client
.schemaBuilder()
Expand Down

0 comments on commit fb30ad5

Please sign in to comment.