github / github/codeql-cli-binaries

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

Offen
#78 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
CLI
Vorherrschende Sprache
Keine Sprachdaten
Sterne
1k
Forks
184
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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)

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.