lintel 0.2.0
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | List of all members
lintel::RegexUtils Class Reference

#include <RegexUtils.h>

Static Public Member Functions

static bool validatePattern (const std::string &pattern, std::string &errorMessage)
 
static bool matches (const std::string &pattern, const std::string &text)
 

Static Public Attributes

static constexpr std::size_t kMaxPatternLength = 128
 

Detailed Description

Hardening helpers for user-supplied regular expressions.

std::regex is vulnerable to catastrophic backtracking ("ReDoS"). These helpers apply a pragmatic heuristic layer before compiling a pattern: length limit, rejection of clearly pathological constructs, and a compilation check. They never throw on invalid input.

Member Function Documentation

◆ matches()

static bool lintel::RegexUtils::matches ( const std::string &  pattern,
const std::string &  text 
)
static

Match text against a user-supplied pattern using the hardened checks. Never throws; returns false for invalid/unsafe patterns.

Parameters
patternthe pattern to match
textthe text to match against
Returns
true if the pattern is safe and matches

◆ validatePattern()

static bool lintel::RegexUtils::validatePattern ( const std::string &  pattern,
std::string &  errorMessage 
)
static

Validate a user-supplied pattern against basic ReDoS heuristics.

Parameters
patternthe pattern to check
errorMessagereceives a human-readable reason on failure
Returns
true if the pattern is safe to compile

Member Data Documentation

◆ kMaxPatternLength

constexpr std::size_t lintel::RegexUtils::kMaxPatternLength = 128
staticconstexpr

Maximum allowed length of a user-supplied pattern.


The documentation for this class was generated from the following file: