-
Notifications
You must be signed in to change notification settings - Fork 161
Open
Labels
Description
What do you think about adding predicates to the CodeQL type string for determining whether a string has a given prefix or suffix or contains a substring? For example startsWith(string), endsWith(string) and contains(string).
Currently the workarounds are using indexOf(...) = 0 or matches(...%) (which seems to be faster than indexOf, see github/codeql#6479 (comment)). However, these predicates do not convey the intention as clearly, might not be that performant and for matches one must take care not to accidentally use %or _ where the intention was to match them literally.
In the github/codeql repository (at github/codeql@3953331) there are at least:
- 196 cases where
startsWithcould be used
(I searched for the regexmatches\("[^%_]*%"\)in CodeQL source files) - 72 cases where
endsWithcould be used
(I searched for the regexmatches\("%[^%_]*"\)in CodeQL source files)
alexkreidler