mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-11 10:46:25 +03:00
handle capital letters and quotes in Raw SQL Track this (#1811)
This commit is contained in:
parent
97ac88edb5
commit
2bc2c40532
@ -2,14 +2,23 @@ const createSQLRegex = /create\s*(?:|or\s*replace)\s*(view|table|function)\s*((\
|
|||||||
|
|
||||||
const createSQLRegexNoFunction = /create\s*(?:|or\s*replace)\s*(view|table)\s*((\"?\w+\"?)\.(\"?\w+\"?)|(\"?\w+\"?))/; // eslint-disable-line
|
const createSQLRegexNoFunction = /create\s*(?:|or\s*replace)\s*(view|table)\s*((\"?\w+\"?)\.(\"?\w+\"?)|(\"?\w+\"?))/; // eslint-disable-line
|
||||||
|
|
||||||
|
const getSQLValue = value => {
|
||||||
|
const quotedStringRegex = /^".*"$/;
|
||||||
|
|
||||||
|
let sqlValue = value;
|
||||||
|
if (!quotedStringRegex.test(value)) {
|
||||||
|
sqlValue = value.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return sqlValue.replace(/['"]+/g, '');
|
||||||
|
};
|
||||||
|
|
||||||
const parseCreateSQL = (sql, allowFunction) => {
|
const parseCreateSQL = (sql, allowFunction) => {
|
||||||
const _objects = [];
|
const _objects = [];
|
||||||
|
|
||||||
const formattedSQL = sql.toLowerCase();
|
|
||||||
|
|
||||||
const regExp = allowFunction ? createSQLRegex : createSQLRegexNoFunction;
|
const regExp = allowFunction ? createSQLRegex : createSQLRegexNoFunction;
|
||||||
|
|
||||||
const matches = formattedSQL.match(new RegExp(regExp, 'gmi'));
|
const matches = sql.match(new RegExp(regExp, 'gmi'));
|
||||||
if (matches) {
|
if (matches) {
|
||||||
matches.forEach(element => {
|
matches.forEach(element => {
|
||||||
const itemMatch = element.match(new RegExp(regExp, 'i'));
|
const itemMatch = element.match(new RegExp(regExp, 'i'));
|
||||||
@ -32,8 +41,8 @@ const parseCreateSQL = (sql, allowFunction) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_object.type = type.toLowerCase();
|
_object.type = type.toLowerCase();
|
||||||
_object.name = name.replace(/['"]+/g, '').trim();
|
_object.name = getSQLValue(name);
|
||||||
_object.schema = schema.replace(/['"]+/g, '').trim();
|
_object.schema = getSQLValue(schema);
|
||||||
|
|
||||||
_objects.push(_object);
|
_objects.push(_object);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user