github / github/codeql-cli-binaries

Add `string` predicates `startsWith`, `endsWith` and `contains`

Open
#78 2 comments 1 reaction 0 assignees View on GitHub
CLI
Dominant language
No language data
Stars
1k
Forks
184
PR merge metrics
No merged PRs in 30d

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 https://github.com/github/codeql/issues/6479#issuecomment-900081363). 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 https://github.com/github/codeql/commit/39533317ffbeb6224d049de22fc182d8eeea4b61) there are at least:
- 196 cases where `startsWith` could be used
(I searched for the regex `matches\("[^%_]*%"\)` in CodeQL source files)
- 72 cases where `endsWith` could be used
(I searched for the regex `matches\("%[^%_]*"\)` in CodeQL source files)

Contributor guide

Open the contributing guide

Research direction

The issue proposes adding startsWith, endsWith, and contains predicates to the CodeQL string type, but names no source files, tests, or implementation entry points. Begin by locating the string type implementation and its tests; done means the predicates are available and cover prefix, suffix, and substring checks without relying on indexOf or matches workarounds.

Written by the indexing model from the issue text.

Assessment

Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.