1010
1111import ql
1212
13+ AstNode getASubExpression ( Select sel ) {
14+ result = sel .getExpr ( _)
15+ or
16+ result = getASubExpression ( sel ) .getAChild ( )
17+ }
18+
1319/** Gets the `index`th part of the select statement. */
1420private AstNode getSelectPart ( Select sel , int index ) {
1521 result =
1622 rank [ index ] ( AstNode n , Location loc |
1723 (
18- n . getParent * ( ) = sel . getExpr ( _ ) and loc = n .getLocation ( )
24+ n = getASubExpression ( sel ) and loc = n .getLocation ( )
1925 or
2026 // the strings are behind a predicate call.
21- exists ( Call c , Predicate target |
22- c .getParent * ( ) = sel .getExpr ( _) and loc = c .getLocation ( )
23- |
27+ exists ( Call c , Predicate target | c = getASubExpression ( sel ) and loc = c .getLocation ( ) |
2428 c .getTarget ( ) = target and
2529 (
2630 target .getBody ( ) .( ComparisonFormula ) .getAnOperand ( ) = n
@@ -30,6 +34,14 @@ private AstNode getSelectPart(Select sel, int index) {
3034 )
3135 )
3236 )
37+ or
38+ // the string is a variable that is assigned in the `where` clause.
39+ exists ( VarAccess v , ComparisonFormula comp , String str |
40+ v = getASubExpression ( sel ) and
41+ loc = v .getLocation ( ) and
42+ comp .hasOperands ( v .getDeclaration ( ) .getAnAccess ( ) , str ) and
43+ n = str
44+ )
3345 )
3446 |
3547 n
@@ -52,7 +64,7 @@ private AstNode getSelectPart(Select sel, int index) {
5264String shouldHaveFullStop ( Select sel ) {
5365 result =
5466 max ( AstNode str , int i |
55- str .getParent + ( ) = sel .getExpr ( 1 ) and str = getSelectPart ( sel , i )
67+ str .getParent * ( ) = sel .getMessage ( ) and str = getSelectPart ( sel , i )
5668 |
5769 str order by i
5870 ) and
@@ -73,7 +85,7 @@ String shouldHaveFullStop(Select sel) {
7385String shouldStartCapital ( Select sel ) {
7486 result =
7587 min ( AstNode str , int i |
76- str .getParent + ( ) = sel .getExpr ( 1 ) and str = getSelectPart ( sel , i )
88+ str .getParent * ( ) = sel .getMessage ( ) and str = getSelectPart ( sel , i )
7789 |
7890 str order by i
7991 ) and
@@ -164,6 +176,14 @@ String wrongFlowsPhrase(Select sel, string kind) {
164176 )
165177}
166178
179+ /**
180+ * Gets a string element that contains double whitespace.
181+ */
182+ String doubleWhitespace ( Select sel ) {
183+ result = getSelectPart ( sel , _) and
184+ result .getValue ( ) .regexpMatch ( ".*\\s\\s.*" )
185+ }
186+
167187from AstNode node , string msg
168188where
169189 not node .getLocation ( ) .getFile ( ) .getAbsolutePath ( ) .matches ( "%/test/%" ) and
@@ -194,5 +214,8 @@ where
194214 or
195215 node = wrongFlowsPhrase ( _, "taint" ) and
196216 msg = "Use \"depends on\" instead of \"flows to\" in taint tracking queries."
217+ or
218+ node = doubleWhitespace ( _) and
219+ msg = "Avoid using double whitespace in alert messages."
197220 )
198221select node , msg
0 commit comments