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

Commit c6e41928 by Rémi Weislinger Committed by GitHub

fix(postgres): parse enums correctly when describing a table (#12409)

1 parent e33d2bdc
......@@ -798,7 +798,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
return [];
}
matches = matches.map(m => m.replace(/",$/, '').replace(/,$/, '').replace(/(^"|"$)/, ''));
matches = matches.map(m => m.replace(/",$/, '').replace(/,$/, '').replace(/(^"|"$)/g, ''));
return matches.slice(0, -1);
}
......
......@@ -1265,5 +1265,45 @@ if (dialect.startsWith('postgres')) {
});
});
});
describe('fromArray()', () => {
beforeEach(function() {
this.queryGenerator = new QueryGenerator({
sequelize: this.sequelize,
_dialect: this.sequelize.dialect
});
});
const tests = [
{
title: 'should convert an enum with no quoted strings to an array',
arguments: '{foo,bar,foobar}',
expectation: ['foo', 'bar', 'foobar']
}, {
title: 'should convert an enum starting with a quoted string to an array',
arguments: '{"foo bar",foo,bar}',
expectation: ['foo bar', 'foo', 'bar']
}, {
title: 'should convert an enum ending with a quoted string to an array',
arguments: '{foo,bar,"foo bar"}',
expectation: ['foo', 'bar', 'foo bar']
}, {
title: 'should convert an enum with a quoted string in the middle to an array',
arguments: '{foo,"foo bar",bar}',
expectation: ['foo', 'foo bar', 'bar']
}, {
title: 'should convert an enum full of quoted strings to an array',
arguments: '{"foo bar","foo bar","foo bar"}',
expectation: ['foo bar', 'foo bar', 'foo bar']
}
];
_.each(tests, test => {
it(test.title, function() {
const convertedText = this.queryGenerator.fromArray(test.arguments);
expect(convertedText).to.deep.equal(test.expectation);
});
});
});
});
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!