Skip to content

Commit

Permalink
Merge pull request #2 from tmukammel/fix001
Browse files Browse the repository at this point in the history
Fix001: Escape chars in query
  • Loading branch information
tmukammel authored Mar 16, 2021
2 parents 3c20495 + 2505bd4 commit c9f589f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequelize-query",
"version": "1.0.2",
"version": "1.0.3",
"description": "Sequelize query parser",
"main": "sequelizeQueryParser.js",
"scripts": {
Expand Down
26 changes: 19 additions & 7 deletions sequelizeQueryParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,27 @@ module.exports = function (db) {
// console.debug("After Key:", key, " Query fields: ", JSON.stringify(json, null, 4))
});
}

/**
* Unescape escaped sequences in string.
* @param {*} query string with escape sequence
* @returns {string} unescaped string
*/
const unescapeEscapedQuery = (query) => {
const queryString = query.toString();
const queryStringUnescaped = unescape(queryString);
return queryStringUnescaped;
}

/**
* Parse and build Sequelize format query
* @param {JSON} query
* @returns {JSON} sequelize formatted DB query params JSON
*/
const parseQueryFields = (query) => {
let json = JSON.parse(query.toString());
let json = JSON.parse(unescapeEscapedQuery(query));
iterativeReplace(json);
console.debug("Resultent query fields: ", json);
// console.debug("Resultent query fields: ", json);
return json;
}

Expand All @@ -152,9 +163,9 @@ module.exports = function (db) {
* @returns {JSON} sequelize formatted DB include params JSON
*/
const parseIncludeFields = (query) => {
let json = JSON.parse(query.toString());
let json = JSON.parse(unescapeEscapedQuery(query));
iterativeReplace(json);
console.debug("Resultent include fields: ", json);
// console.debug("Resultent include fields: ", json);
return json;
}

Expand All @@ -170,11 +181,11 @@ module.exports = function (db) {
var param = {};
param[operators[elements[0]]] = elements[1]

console.debug("Query param: ", param);
// console.debug("Query param: ", param);
return param;
}
else {
console.debug("Query param: ", elements[0]);
// console.debug("Query param: ", elements[0]);
return elements[0];
}
}
Expand Down Expand Up @@ -268,7 +279,8 @@ module.exports = function (db) {

dbQuery.offset = offset * limit;

console.debug("Query: ", JSON.stringify(dbQuery, null, 4));
console.debug("Final sequelize query:");
console.debug(JSON.stringify(dbQuery, null, 4));

resolve(dbQuery);
}
Expand Down

0 comments on commit c9f589f

Please sign in to comment.