Support querying tables with column names with multiple apostrophes (issue #934). Includes integration test.

remotes/origin/cdb-6.1
Jens Kristian Geyti 9 years ago
parent 99a0dce688
commit 02c47f5071

@ -70,7 +70,10 @@ var inlineParser = function(fieldName, i) {
//fields containing single quotes will break
//the evaluated javascript unless they are escaped
//see https://github.com/brianc/node-postgres/issues/507
fieldName.replace("'", "\\'") +
//Addendum: However, we need to make sure to replace all
//occurences of apostrophes, not just the first one.
//See https://github.com/brianc/node-postgres/issues/934
fieldName.replace(/'/g, "\\'") +
"'] = " +
"rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);";
};

@ -0,0 +1,13 @@
var helper = require(__dirname + '/../test-helper');
var pg = helper.pg;
test('support for complex column names', function() {
pg.connect(helper.config, assert.success(function(client, done) {
client.query("CREATE TEMP TABLE t ( \"complex''column\" TEXT )");
client.query('SELECT * FROM t', assert.success(function(res) {
done();
assert.strictEqual(res.fields[0].name, "complex''column");
pg.end();
}));
}));
});
Loading…
Cancel
Save