Skip to content

Commit

Permalink
guarding regex call (#805)
Browse files Browse the repository at this point in the history
* guarding regex call

* lint

---------

Co-authored-by: Daniel Lemire <dlemire@lemire.me>
  • Loading branch information
lemire and Daniel Lemire authored Dec 20, 2024
1 parent 0062fd2 commit 776f670
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/url_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,21 @@ std::string generate_segment_wildcard_regexp(

bool protocol_component_matches_special_scheme(
ada::url_pattern_component& component) {
// TODO: Optimize this.
auto regex = component.get_regexp();
std::regex rx(regex.data(), regex.size());
std::cmatch cmatch;
return std::regex_match("http", cmatch, rx) ||
try {
std::regex rx(regex.data(), regex.size());
std::cmatch cmatch;
return std::regex_match("http", cmatch, rx) ||
std::regex_match("https", cmatch, rx) ||
std::regex_match("ws", cmatch, rx) ||
std::regex_match("wss", cmatch, rx) ||
std::regex_match("ftp", cmatch, rx);
} catch (...) {
// You probably want to log this error.
ada_log("Error while matching protocol component with special scheme");
ada_log("Regex Input: ", input);
return false;
}
}

} // namespace url_pattern_helpers
Expand Down

0 comments on commit 776f670

Please sign in to comment.