不要怂,就是干,撸起袖子干!

Commit 263ddba0 by Mick Hansen

fix(model#findOrCreate): escape $ inside insertQuery

1 parent ce6f5729
......@@ -74,8 +74,12 @@ $ sudo docker pull mhansen/sequelize-contribution
Start the container and save references to container id and ip:
```console
# Start mysql/postgres container
$ CONTAINER=$(sudo docker run -d -i -t mhansen/sequelize-contribution)
$ CONTAINER_IP=$(sudo docker inspect -format='{{.NetworkSettings.IPAddress}}' $CONTAINER)
# Or start postgres 9.4 container
$ CONTAINER=$(sudo docker run --name sequelize-postgres -e POSTGRES_USER=sequelize_test -e POSTGRES_PASSWORD=sequelize_test -d postgres:9.4)
$ CONTAINER_IP=$(sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' $CONTAINER)
```
Run tests:
......
......@@ -238,7 +238,12 @@ module.exports = (function() {
identityWrapperRequired = true;
}
values.push(this.escape(value, (modelAttributeMap && modelAttributeMap[key]) || undefined));
value = this.escape(value, (modelAttributeMap && modelAttributeMap[key]) || undefined);
if (options.exception) {
// $ inside value strings are illegal when using $$ as literal strings/delimiters for function bodys
value = value.replace(/\$/g, '\\$');
}
values.push(value);
}
}
}
......
......@@ -107,6 +107,29 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
it('should support special characters in defaults', function () {
var User = this.sequelize.define('user', {
objectId: {
type: DataTypes.INTEGER,
unique: true
},
description: {
type: DataTypes.TEXT
}
});
return User.sync({force: true}).then(function () {
return User.findOrCreate({
where: {
objectId: 1
},
defaults: {
description: '$$ and !! and :: and ? and ^ and * and \''
}
});
});
});
it('returns instance if already existent. Single find field.', function(done) {
var self = this,
data = {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!