Fix exception caused by column names with single quotes
Also rename some test files so they match the Makefile regex. They will be included in the test suite from now on.
This commit is contained in:
parent
8abf59a632
commit
5f592a1240
@ -65,7 +65,12 @@ Result.prototype.addRow = function(row) {
|
||||
};
|
||||
|
||||
var inlineParser = function(fieldName, i) {
|
||||
return "\nthis['" + fieldName + "'] = " +
|
||||
return "\nthis['" +
|
||||
//fields containing single quotes will break
|
||||
//the evaluated javascript unless they are escaped
|
||||
//see https://github.com/brianc/node-postgres/issues/507
|
||||
fieldName.replace("'", "\\'") +
|
||||
"'] = " +
|
||||
"rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);";
|
||||
};
|
||||
|
||||
|
@ -2,7 +2,7 @@ var helper = require(__dirname + "/../test-helper");
|
||||
var pg = helper.pg;
|
||||
|
||||
test('parsing array results', function() {
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
pg.connect(helper.config, assert.calls(function(err, client, done) {
|
||||
assert.isNull(err);
|
||||
client.query("CREATE TEMP TABLE why(names text[], numbors integer[], decimals double precision[])");
|
||||
client.query('INSERT INTO why(names, numbors, decimals) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\', \'{.1, 0.05, 3.654}\')').on('error', console.log);
|
||||
@ -12,6 +12,7 @@ test('parsing array results', function() {
|
||||
assert.equal(result.rows[0].decimals[0], 0.1);
|
||||
assert.equal(result.rows[0].decimals[1], 0.05);
|
||||
assert.equal(result.rows[0].decimals[2], 3.654);
|
||||
done()
|
||||
pg.end();
|
||||
}))
|
||||
})
|
15
test/integration/gh-issues/507-tests.js
Normal file
15
test/integration/gh-issues/507-tests.js
Normal file
@ -0,0 +1,15 @@
|
||||
var helper = require(__dirname + "/../test-helper");
|
||||
var pg = helper.pg;
|
||||
|
||||
test('parsing array results', function() {
|
||||
pg.connect(helper.config, assert.success(function(client, done) {
|
||||
client.query('CREATE TEMP TABLE test_table(bar integer, "baz\'s" integer)')
|
||||
client.query('INSERT INTO test_table(bar, "baz\'s") VALUES(1, 1), (2, 2)')
|
||||
client.query('SELECT * FROM test_table', function(err, res) {
|
||||
assert.equal(res.rows[0]["baz's"], 1)
|
||||
assert.equal(res.rows[1]["baz's"], 2)
|
||||
done()
|
||||
pg.end()
|
||||
})
|
||||
}))
|
||||
})
|
Loading…
Reference in New Issue
Block a user