Skip to content

Add string predicates startsWith, endsWith and contains #78

@Marcono1234

Description

@Marcono1234

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 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions