@@ -9,11 +9,13 @@ module;
99import java
1010
1111/**
12- * A module importing the frameworks that implement `RegexMatch`es ,
12+ * A module importing the frameworks that implement string matches ,
1313 * ensuring that they are visible to the concepts library.
1414 */
1515private module Frameworks {
1616 private import semmle.code.java.JDK
17+ private import semmle.code.java.frameworks.apache.Lang
18+ private import semmle.code.java.frameworks.guava.Guava
1719 private import semmle.code.java.frameworks.JavaxAnnotations
1820}
1921
@@ -79,3 +81,207 @@ module RegexMatch {
7981 abstract string getName ( ) ;
8082 }
8183}
84+
85+ /**
86+ * An expression that tests whether an input string contains a substring.
87+ *
88+ * Extend this class to refine existing API models. If you want to model new APIs,
89+ * extend `StringSubstringMatch::Range` instead.
90+ */
91+ class StringSubstringMatch extends Expr instanceof StringSubstringMatch:: Range {
92+ /** Gets the input string being tested. */
93+ Expr getInputString ( ) { result = super .getInputString ( ) }
94+
95+ /** Gets the expression that specifies the substring. */
96+ Expr getMatchExpression ( ) { result = super .getMatchExpression ( ) }
97+
98+ /** Gets an expression to be sanitized. */
99+ Expr getASanitizedExpr ( ) { result = [ this .getInputString ( ) , super .getAdditionalSanitizedExpr ( ) ] }
100+
101+ /** Holds if taking `branch` means that the input contains the substring. */
102+ predicate hasSubstringOnBranch ( boolean branch ) { super .hasSubstringOnBranch ( branch ) }
103+
104+ /** Gets a descriptive name for this substring match. */
105+ string getName ( ) { result = super .getName ( ) }
106+ }
107+
108+ /** Provides classes for modeling substring-matching APIs. */
109+ module StringSubstringMatch {
110+ /** A range class for APIs that test whether an input contains a substring. */
111+ abstract class Range extends Expr {
112+ /** Gets the input string being tested. */
113+ abstract Expr getInputString ( ) ;
114+
115+ /** Gets the expression that specifies the substring. */
116+ abstract Expr getMatchExpression ( ) ;
117+
118+ /** Gets an additional expression to be sanitized, if any. */
119+ Expr getAdditionalSanitizedExpr ( ) { none ( ) }
120+
121+ /** Holds if taking `branch` means that the input contains the substring. */
122+ abstract predicate hasSubstringOnBranch ( boolean branch ) ;
123+
124+ /** Gets a descriptive name for this substring match. */
125+ abstract string getName ( ) ;
126+ }
127+ }
128+
129+ /**
130+ * An expression that tests whether an input string contains characters from a
131+ * character set.
132+ *
133+ * Extend this class to refine existing API models. If you want to model new APIs,
134+ * extend `StringCharacterSetMatch::Range` instead.
135+ */
136+ class StringCharacterSetMatch extends Expr instanceof StringCharacterSetMatch:: Range {
137+ /** Gets the input string being tested. */
138+ Expr getInputString ( ) { result = super .getInputString ( ) }
139+
140+ /** Gets the expression that specifies the character set. */
141+ Expr getMatchExpression ( ) { result = super .getMatchExpression ( ) }
142+
143+ /** Gets an expression to be sanitized. */
144+ Expr getASanitizedExpr ( ) { result = [ this .getInputString ( ) , super .getAdditionalSanitizedExpr ( ) ] }
145+
146+ /**
147+ * Holds if taking `branch` means that the input contains at least one
148+ * character from the match expression.
149+ */
150+ predicate hasMatchingCharacterOnBranch ( boolean branch ) {
151+ super .hasMatchingCharacterOnBranch ( branch )
152+ }
153+
154+ /** Gets a descriptive name for this character-set match. */
155+ string getName ( ) { result = super .getName ( ) }
156+ }
157+
158+ /** Provides classes for modeling character-set matching APIs. */
159+ module StringCharacterSetMatch {
160+ /**
161+ * A range class for APIs that test whether an input contains characters from
162+ * a character set.
163+ */
164+ abstract class Range extends Expr {
165+ /** Gets the input string being tested. */
166+ abstract Expr getInputString ( ) ;
167+
168+ /** Gets the expression that specifies the character set. */
169+ abstract Expr getMatchExpression ( ) ;
170+
171+ /** Gets an additional expression to be sanitized, if any. */
172+ Expr getAdditionalSanitizedExpr ( ) { none ( ) }
173+
174+ /**
175+ * Holds if taking `branch` means that the input contains at least one
176+ * character from the match expression.
177+ */
178+ abstract predicate hasMatchingCharacterOnBranch ( boolean branch ) ;
179+
180+ /** Gets a descriptive name for this character-set match. */
181+ abstract string getName ( ) ;
182+ }
183+ }
184+
185+ /**
186+ * An expression that replaces every occurrence of a target in a string.
187+ *
188+ * Extend this class to refine existing API models. If you want to model new APIs,
189+ * extend `StringReplacement::Range` instead.
190+ */
191+ class StringReplacement extends Expr instanceof StringReplacement:: Range {
192+ /** Gets the input string whose contents are replaced. */
193+ Expr getInputString ( ) { result = super .getInputString ( ) }
194+
195+ /** Gets the expression that identifies the content to replace. */
196+ Expr getMatchExpression ( ) { result = super .getMatchExpression ( ) }
197+
198+ /** Gets the replacement expression. */
199+ Expr getReplacement ( ) { result = super .getReplacement ( ) }
200+
201+ /** Holds if the match expression is interpreted as a regular expression. */
202+ predicate matchExpressionIsRegex ( ) { super .matchExpressionIsRegex ( ) }
203+
204+ /** Holds if each character in the match expression is matched independently. */
205+ predicate matchExpressionIsCharacterSet ( ) { super .matchExpressionIsCharacterSet ( ) }
206+
207+ /** Gets a descriptive name for this replacement operation. */
208+ string getName ( ) { result = super .getName ( ) }
209+ }
210+
211+ /** Provides classes for modeling string-replacement APIs. */
212+ module StringReplacement {
213+ /**
214+ * An expression that replaces every occurrence of a target in a string.
215+ *
216+ * Extend this class to model new APIs. If you want to refine existing API models,
217+ * extend `StringReplacement` instead.
218+ */
219+ abstract class Range extends Expr {
220+ /** Gets the input string whose contents are replaced. */
221+ abstract Expr getInputString ( ) ;
222+
223+ /** Gets the expression that identifies the content to replace. */
224+ abstract Expr getMatchExpression ( ) ;
225+
226+ /** Gets the replacement expression. */
227+ abstract Expr getReplacement ( ) ;
228+
229+ /** Holds if the match expression is interpreted as a regular expression. */
230+ predicate matchExpressionIsRegex ( ) { none ( ) }
231+
232+ /** Holds if each character in the match expression is matched independently. */
233+ predicate matchExpressionIsCharacterSet ( ) { none ( ) }
234+
235+ /** Gets a descriptive name for this replacement operation. */
236+ abstract string getName ( ) ;
237+ }
238+ }
239+
240+ /**
241+ * An expression that removes every occurrence of a target from a string.
242+ *
243+ * Extend this class to refine existing API models. If you want to model new APIs,
244+ * extend `StringRemoval::Range` instead.
245+ */
246+ class StringRemoval extends Expr instanceof StringRemoval:: Range {
247+ /** Gets the input string whose contents are removed. */
248+ Expr getInputString ( ) { result = super .getInputString ( ) }
249+
250+ /** Gets the expression that identifies the content to remove. */
251+ Expr getMatchExpression ( ) { result = super .getMatchExpression ( ) }
252+
253+ /** Holds if the match expression is interpreted as a regular expression. */
254+ predicate matchExpressionIsRegex ( ) { super .matchExpressionIsRegex ( ) }
255+
256+ /** Holds if each character in the match expression is matched independently. */
257+ predicate matchExpressionIsCharacterSet ( ) { super .matchExpressionIsCharacterSet ( ) }
258+
259+ /** Gets a descriptive name for this removal operation. */
260+ string getName ( ) { result = super .getName ( ) }
261+ }
262+
263+ /** Provides classes for modeling string-removal APIs. */
264+ module StringRemoval {
265+ /**
266+ * An expression that removes every occurrence of a target from a string.
267+ *
268+ * Extend this class to model new APIs. If you want to refine existing API models,
269+ * extend `StringRemoval` instead.
270+ */
271+ abstract class Range extends Expr {
272+ /** Gets the input string whose contents are removed. */
273+ abstract Expr getInputString ( ) ;
274+
275+ /** Gets the expression that identifies the content to remove. */
276+ abstract Expr getMatchExpression ( ) ;
277+
278+ /** Holds if the match expression is interpreted as a regular expression. */
279+ predicate matchExpressionIsRegex ( ) { none ( ) }
280+
281+ /** Holds if each character in the match expression is matched independently. */
282+ predicate matchExpressionIsCharacterSet ( ) { none ( ) }
283+
284+ /** Gets a descriptive name for this removal operation. */
285+ abstract string getName ( ) ;
286+ }
287+ }
0 commit comments