badges/shields · error · InvalidParameter
Invalid flags, must be one of: ${VALID_FLAGS}
Error message
Invalid flags, must be one of: ${VALID_FLAGS} What it means
This InvalidParameter is thrown by the dynamic-regex (dynamic/json-regex style) service's validate step when the flags query parameter contains any character not present in VALID_FLAGS (the single-character regex modifiers allowed, e.g. 'i' and 'g'). Flags must be a string whose every character is an accepted regex flag. The check runs before any regex is compiled.
Source
Thrown at services/dynamic/dynamic-regex.service.js:73
required: false,
example: '$<amount>/$1',
},
{
name: 'flags',
description:
'Flags to be used when creating the regex: `i` = case-insensitive, `m` = multi-line mode, `s` = dot matches linebreaks. None by default.',
required: false,
example: VALID_FLAGS,
},
),
},
},
}
static defaultBadgeData = { label: 'match' }
static validate(flags) {
if (flags?.split('')?.some(c => VALID_FLAGS.indexOf(c) === -1)) {
throw new InvalidParameter({
prettyMessage: `Invalid flags, must be one of: ${VALID_FLAGS}`,
})
}
}
static transform(buffer, search, replace, flags) {
// build re2 regex
let re2
try {
re2 = new RE2(search, flags)
} catch (error) {
if (error instanceof SyntaxError) {
throw new InvalidParameter({
prettyMessage: `Invalid re2 regex: ${error.message}`,
})
}
throw error
}View on GitHub (pinned to 766fd8bc89)
Solutions
- Restrict the flags parameter to characters listed in VALID_FLAGS (e.g. i, g).
- Remove unsupported modifiers from the URL; emulate multiline behavior within the regex body if needed.
- URL-encode the flags value to avoid stray characters/space corruption.
Example fix
// before /badge/dynamic/json.svg?url=...&query=...&search=version&replace=$1&flags=igm // after /badge/dynamic/json.svg?url=...&query=...&search=version&replace=$1&flags=gi
Defensive patterns
Strategy: validation
Validate before calling
const VALID_FLAGS = 'ig';
function validateFlags(flags) {
if (flags && [...flags].some(c => !VALID_FLAGS.includes(c))) {
throw new Error(`Invalid flags, must be one of: ${VALID_FLAGS}`);
}
}
validateFlags('gi'); // ok before calling the service Type guard
function hasValidFlags(flags) {
return flags === undefined || [...flags].every(c => 'ig'.includes(c));
} Prevention
- Use only single-character flags accepted by the service (check VALID_FLAGS in the source).
- Do not copy PCRE modifiers (m, s, u, x) into the flags parameter.
- URL-encode flag values to avoid stray characters.
When it happens
Trigger: Passing flags such as flags=m (unsupported modifier), flags=igm (contains unsupported 'm'), flags with spaces, or multi-letter flags like flags=giu where 'u' is not in VALID_FLAGS.
Common situations: Copying flags from PCRE/JS docs that include unsupported modifiers (m, s, u, x); combining flags as words ('global') instead of single letters; typos in badge URLs.
Related errors
- Invalid re2 regex: ${error.message}
- Field `idSuffix` must contain only numbers, letters, -, and
- invalid api key
- monitor API key is unvalid
- must use a monitor-specific api key
AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30).
Data as JSON: /api/errors/85a558318e52cf17.
Report an issue: GitHub.