Skip to content

Commit

Permalink
fix: unable to index json filed named userId
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypa committed Dec 13, 2024
1 parent 8285f15 commit 7d7203e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/utils/sharedUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const VARIABLE_REGEX = /^[a-zA-Z_]\w*$/; // vars of form aA4_f allowed
export function getColumNameForJsonField(jsonField) {
// ignoring sonar security error as md5 function is not used for security
// Md5 function is used here to increase the length of jsonfield to more than 64 characters
return crypto.createHash('md5').update(jsonField).digest('hex'); //NOSONAR
const hash = crypto.createHash('md5').update(jsonField).digest('hex'); //NOSONAR
return "col_" + hash;
}

export function isAlphaNumChar(char) {
char = char.charCodeAt(0);
if (!(char > 47 && char < 58) && // numeric (0-9)
Expand Down Expand Up @@ -69,4 +69,4 @@ export function isNestedVariableNameLike(nameToTest) {
}
}
return true;
}
}
4 changes: 2 additions & 2 deletions test/unit/utils/db-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ describe('Unit tests for db.js', function () {
const tableName = 'test.hello';
await deleteDocuments(tableName, "$.x<10 AND $.hotel.name='oyo'", ['hotel.name']);
expect(savedSql).to.eql("DELETE FROM test.hello WHERE document->>\"$.x\"<10" +
" AND b978c733175ca5d9503b1cc095eece1f='oyo';");
" AND col_b978c733175ca5d9503b1cc095eece1f='oyo';");
mockedFunctions.connection.execute = saveExecute;
});
});
Expand Down Expand Up @@ -2566,7 +2566,7 @@ describe('Unit tests for db.js', function () {
await _validateQueryPass("$.s<10 && !$.j.k || $.y!='hello'",
["s", "j.k"],
"SELECT documentID,document FROM test.customer " +
"WHERE 03c7c0ace395d80182db07ae2c30f034<10 && !91e12519d4a93e0ce72a98c42383e747 " +
"WHERE col_03c7c0ace395d80182db07ae2c30f034<10 && !col_91e12519d4a93e0ce72a98c42383e747 " +
"|| document->>\"$.y\"!='hello' LIMIT 1000");
});

Expand Down
3 changes: 2 additions & 1 deletion test/unit/utils/query-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ describe('Query Utils test', function () {

it('should transformCocoToSQLQuery success cases with index field', function () {
expect(Query.transformCocoToSQLQuery("$.y>5 || $.x > 10 && $.price.tax = 18", ["x", "price.tax"]))
.to.eql('document->>"$.y">5 || 9dd4e461268c8034f5c8564e155c67a6 > 10 && 6a1a731895e201b727851bc567ac1e8a = 18');
// eslint-disable-next-line max-len
.to.eql('document->>"$.y">5 || col_9dd4e461268c8034f5c8564e155c67a6 > 10 && col_6a1a731895e201b727851bc567ac1e8a = 18');
});

it('should transformCocoToSQLQuery error cases', function () {
Expand Down

0 comments on commit 7d7203e

Please sign in to comment.