@@ -232,6 +232,11 @@ export function convertToSemVer(version: string, logger: Logger): string {
232232 * name or URL of the bundle asset for their platform: the appropriate bundle for the runner's OS,
233233 * and the best compression method it supports, are selected automatically, in the same way as
234234 * they are for the default and `linked` versions of the tools.
235+ *
236+ * `semver.valid` only succeeds if the *entire* input string is a valid semantic version, and the
237+ * semantic versioning spec never permits `:` or `/` characters in a version string. Since every
238+ * URL contains `://`, a CodeQL Bundle URL can never be misidentified as a bare CLI version number
239+ * by this function.
235240 */
236241function tryGetCliVersionFromToolsInput (
237242 toolsInput : string ,
@@ -263,6 +268,11 @@ function tryGetLatestOffsetFromToolsInput(
263268 * A range must contain a `.`, so that bare numbers or strings such as `2` or `20200601` are not
264269 * misinterpreted as version ranges and are instead handled as local paths, as they were before
265270 * version ranges were supported.
271+ *
272+ * As with `tryGetCliVersionFromToolsInput`, this delegates to `semver.validRange`, which also
273+ * requires the whole input string to be a syntactically valid range and never permits `:` or `/`
274+ * characters. A CodeQL Bundle URL, which always contains `://`, can therefore never be
275+ * misidentified as a version range here either.
266276 */
267277function tryGetCliVersionRangeFromToolsInput (
268278 toolsInput : string ,
@@ -507,6 +517,30 @@ async function resolveDefaultCliVersion(
507517 * Determines where the CodeQL CLI we want to use comes from. This can be from a local file,
508518 * the Actions toolcache, or a download.
509519 *
520+ * The `tools` input is classified into exactly one of the following mutually exclusive
521+ * categories, listed here in order of precedence:
522+ *
523+ * 1. Not specified: the default CLI version for this environment.
524+ * 2. A reserved keyword: `nightly`/`nightly-latest`, `linked`/`latest`, or `toolcache` (see
525+ * `CODEQL_NIGHTLY_TOOLS_INPUTS`, `CODEQL_BUNDLE_VERSION_ALIAS`, and `CODEQL_TOOLCACHE_INPUT`
526+ * below).
527+ * 3. A URL, i.e. a string starting with `http`: the CodeQL Bundle downloaded from that URL.
528+ * 4. A bare CLI version number, e.g. `2.19.0` or `v2.19.0`: the CodeQL Bundle release
529+ * containing that CLI version (see `tryGetCliVersionFromToolsInput`).
530+ * 5. `latest-<N>`, e.g. `latest-1` or `LATEST-2`: the stable CLI release `N` positions before
531+ * the most recent one (see `tryGetLatestOffsetFromToolsInput`).
532+ * 6. A semantic version range, e.g. `2.24.x`, `2.x`, `~2.24.0`, or `^2.24.0`: the newest stable
533+ * CLI release satisfying that range (see `tryGetCliVersionRangeFromToolsInput`).
534+ * 7. Anything else: a local path to a CodeQL Bundle tarball.
535+ *
536+ * Categories 4-6 are all detected using the `semver` package, which only matches a bare version
537+ * or a range if the *entire* input string conforms to the semantic versioning spec. That spec
538+ * never permits a `:` or `/` character in a version or a range, whereas a URL (category 3) always
539+ * contains `://`. So even though the checks for categories 4-6 don't explicitly exclude URLs,
540+ * they can never match one: a value such as `http://example.com/codeql-bundle-linux64.tar.gz` is
541+ * always resolved as a URL, never as a bare version like `2.19.0` or a range like `2.24.x`, no
542+ * matter what version-like path segments or filenames it contains.
543+ *
510544 * @param toolsInput The argument provided for the `tools` input, if any.
511545 * @param defaultCliVersion The default CLI version that's linked to the CodeQL Action.
512546 * @param rawLanguages Raw set of languages.
@@ -533,7 +567,8 @@ export async function getCodeQLSource(
533567 // If there is an explicit `tools` input, it's not one of the reserved values, it doesn't appear
534568 // to point to a URL, and it isn't a bare CodeQL CLI version number, a `latest-<N>` version
535569 // offset, or a semantic version range, then we assume it is a local path and use the CLI from
536- // there.
570+ // there. See the order-of-operations note in this function's doc comment above for the full
571+ // list of categories and why a URL is never confused with a version number or a range.
537572 // TODO: This appears to misclassify filenames that happen to start with `http` as URLs.
538573 if (
539574 toolsInput &&
0 commit comments