Skip to content

Commit 56ef28e

Browse files
authored
Merge pull request #70 from paustint/bug-69
Queries consecutive left parens not accurately parsed #69
2 parents 08f0619 + 77c9533 commit 56ef28e

File tree

9 files changed

+16007
-9443
lines changed

9 files changed

+16007
-9443
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.2.1
4+
5+
- Queries with multiple consecutive left parens in a where clause were not correctly parsed. (#69)
6+
- Fixed npm reported security vulnerabilities.
7+
38
## 1.2.0
49

510
- Changed compose methods to public to allow external access (#65)

debug/test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
var soqlParserJs = require('./lib');
22

3-
const query = `SELECT Title FROM KnowledgeArticleVersion WHERE PublishStatus = 'online' WITH DATA CATEGORY Geography__c ABOVE usa__c WITH SECURITY_ENFORCED`;
3+
const query = `SELECT Id, Name
4+
FROM Account
5+
WHERE (((Name = '1'
6+
OR Name = '2')
7+
AND Name = '3'))
8+
AND (((Description = '123')
9+
OR (Id = '1'
10+
AND Id = '2')))
11+
AND Id = '1'`;
412
// const query = `
513
// SELECT Id, Name, FORMAT(Amount),
614
// (SELECT Quantity, ListPrice, PricebookEntry.UnitPrice, PricebookEntry.Name FROM OpportunityLineItems)

docs/package-lock.json

Lines changed: 15482 additions & 9025 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"react": "^16.5.2",
1414
"react-copy-to-clipboard": "^5.0.1",
1515
"react-dom": "^16.5.2",
16-
"react-scripts-ts": "3.1.0",
16+
"react-scripts-ts": "^4.0.8",
1717
"react-syntax-highlighter": "^9.0.0",
1818
"soql-parser-js": "^1.2.0"
1919
},
@@ -33,5 +33,11 @@
3333
"@types/react": "^16.4.16",
3434
"@types/react-dom": "^16.0.9",
3535
"typescript": "^3.1.3"
36-
}
36+
},
37+
"browserslist": [
38+
">0.2%",
39+
"not dead",
40+
"not ie <= 11",
41+
"not op_mini all"
42+
]
3743
}

lib/SoqlListener.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,8 @@ export class Listener implements SOQLListener {
10691069
console.log('enterParenthesis:', ctx.text);
10701070
}
10711071
if (this.context.currentItem === 'where' || this.context.currentItem === 'having') {
1072-
this.context.tempData.nextHasOpenParen = true;
1072+
this.context.tempData.nextOpenParenCount = this.context.tempData.nextOpenParenCount || 0;
1073+
this.context.tempData.nextOpenParenCount += 1;
10731074
}
10741075
}
10751076
exitParenthesis(ctx: Parser.ParenthesisContext) {
@@ -1100,10 +1101,10 @@ export class Listener implements SOQLListener {
11001101
const currItem: any = {};
11011102
if (!this.context.tempData.currConditionOperation.left) {
11021103
this.context.tempData.currConditionOperation.left = currItem;
1103-
if (this.context.tempData.nextHasOpenParen) {
1104+
if (this.context.tempData.nextOpenParenCount) {
11041105
currItem.openParen = currItem.openParen || 0;
1105-
currItem.openParen += 1;
1106-
this.context.tempData.nextHasOpenParen = false;
1106+
currItem.openParen += this.context.tempData.nextOpenParenCount;
1107+
this.context.tempData.nextOpenParenCount = 0;
11071108
}
11081109
if (this.context.tempData.nextHasLogicalPrefix) {
11091110
currItem.logicalPrefix = this.context.tempData.nextHasLogicalPrefix;
@@ -1121,10 +1122,10 @@ export class Listener implements SOQLListener {
11211122
const currItem: any = {};
11221123
if (!this.context.tempData.currConditionOperation.left) {
11231124
this.context.tempData.currConditionOperation.left = currItem;
1124-
if (this.context.tempData.nextHasOpenParen) {
1125+
if (this.context.tempData.nextOpenParenCount) {
11251126
currItem.openParen = currItem.openParen || 0;
1126-
currItem.openParen += 1;
1127-
this.context.tempData.nextHasOpenParen = false;
1127+
currItem.openParen += this.context.tempData.nextOpenParenCount;
1128+
this.context.tempData.nextOpenParenCount = 0;
11281129
}
11291130
if (this.context.tempData.nextHasLogicalPrefix) {
11301131
currItem.logicalPrefix = this.context.tempData.nextHasLogicalPrefix;
@@ -1151,10 +1152,10 @@ export class Listener implements SOQLListener {
11511152
const currItem: any = {};
11521153
if (!this.context.tempData.currConditionOperation.left) {
11531154
this.context.tempData.currConditionOperation.left = currItem;
1154-
if (this.context.tempData.nextHasOpenParen) {
1155+
if (this.context.tempData.nextOpenParenCount) {
11551156
currItem.openParen = currItem.openParen || 0;
1156-
currItem.openParen += 1;
1157-
this.context.tempData.nextHasOpenParen = false;
1157+
currItem.openParen += this.context.tempData.nextOpenParenCount;
1158+
this.context.tempData.nextOpenParenCount = 0;
11581159
}
11591160
if (this.context.tempData.nextHasLogicalPrefix) {
11601161
currItem.logicalPrefix = this.context.tempData.nextHasLogicalPrefix;
@@ -1185,10 +1186,10 @@ export class Listener implements SOQLListener {
11851186
const currItem: any = {};
11861187
if (!this.context.tempData.currConditionOperation.left) {
11871188
this.context.tempData.currConditionOperation.left = currItem;
1188-
if (this.context.tempData.nextHasOpenParen) {
1189+
if (this.context.tempData.nextOpenParenCount) {
11891190
currItem.openParen = currItem.openParen || 0;
1190-
currItem.openParen += 1;
1191-
this.context.tempData.nextHasOpenParen = false;
1191+
currItem.openParen += this.context.tempData.nextOpenParenCount;
1192+
this.context.tempData.nextOpenParenCount = 0;
11921193
}
11931194
if (this.context.tempData.nextHasLogicalPrefix) {
11941195
currItem.logicalPrefix = this.context.tempData.nextHasLogicalPrefix;

0 commit comments

Comments
 (0)