diff options
author | Jennifer Peshansky <jennifer.peshansky@mongodb.com> | 2022-06-27 13:30:46 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-27 14:52:18 +0000 |
commit | 468f41278b6b30aa602e81010cf7ef7973d97e4d (patch) | |
tree | 82c1c168aa27fce91b4e39759ced055401f05de2 /src/mongo/shell | |
parent | 16924398f1f7ebc78b94a42371f156de4a3b10ae (diff) | |
download | mongo-468f41278b6b30aa602e81010cf7ef7973d97e4d.tar.gz |
SERVER-67162 Integrate new PCRE2 wrapper
Diffstat (limited to 'src/mongo/shell')
-rw-r--r-- | src/mongo/shell/SConscript | 6 | ||||
-rw-r--r-- | src/mongo/shell/bench.cpp | 62 | ||||
-rw-r--r-- | src/mongo/shell/bench.h | 13 | ||||
-rw-r--r-- | src/mongo/shell/mongo_main.cpp | 12 |
4 files changed, 37 insertions, 56 deletions
diff --git a/src/mongo/shell/SConscript b/src/mongo/shell/SConscript index 650f8f72f1f..9a7ea68c5e9 100644 --- a/src/mongo/shell/SConscript +++ b/src/mongo/shell/SConscript @@ -23,7 +23,8 @@ env.Library( '$BUILD_DIR/mongo/scripting/bson_template_evaluator', ], LIBDEPS_PRIVATE=[ - '$BUILD_DIR/third_party/shim_pcrecpp', + '$BUILD_DIR/mongo/util/pcre_util', + '$BUILD_DIR/mongo/util/pcre_wrapper', ], ) @@ -277,7 +278,6 @@ if not has_option('noshell') and jsEngine: "$BUILD_DIR/mongo/util/processinfo", "$BUILD_DIR/mongo/util/signal_handlers", "$BUILD_DIR/mongo/util/version_impl", - "$BUILD_DIR/third_party/shim_pcrecpp", "benchrun", "encrypted_dbclient" if get_option('ssl') == 'on' else '', "kms_shell" if get_option('ssl') == 'on' else '', @@ -305,8 +305,8 @@ if not has_option('noshell') and jsEngine: "$BUILD_DIR/mongo/s/write_ops/batch_write_types", "$BUILD_DIR/mongo/transport/transport_layer", "$BUILD_DIR/mongo/util/net/ssl_manager", + "$BUILD_DIR/mongo/util/pcre_wrapper", "$BUILD_DIR/mongo/util/signal_handlers", - "$BUILD_DIR/third_party/shim_pcrecpp", "linenoise", "mongo_initializers", "shell_utils", diff --git a/src/mongo/shell/bench.cpp b/src/mongo/shell/bench.cpp index d0c02886304..0c7b257e5de 100644 --- a/src/mongo/shell/bench.cpp +++ b/src/mongo/shell/bench.cpp @@ -32,7 +32,6 @@ #include "mongo/shell/bench.h" -#include <pcrecpp.h> #include <string> #include "mongo/base/shim.h" @@ -45,6 +44,8 @@ #include "mongo/scripting/bson_template_evaluator.h" #include "mongo/stdx/thread.h" #include "mongo/util/md5.h" +#include "mongo/util/pcre.h" +#include "mongo/util/pcre_util.h" #include "mongo/util/time_support.h" #include "mongo/util/timer.h" #include "mongo/util/version.h" @@ -95,21 +96,6 @@ private: BenchRunState& _brState; }; -pcrecpp::RE_Options flags2options(const char* flags) { - pcrecpp::RE_Options options; - options.set_utf8(true); - while (flags && *flags) { - if (*flags == 'i') - options.set_caseless(true); - else if (*flags == 'm') - options.set_multiline(true); - else if (*flags == 'x') - options.set_extended(true); - flags++; - } - return options; -} - bool hasSpecial(const BSONObj& obj) { BSONObjIterator i(obj); while (i.more()) { @@ -673,6 +659,11 @@ BenchRunOp opFromBson(const BSONObj& op) { void BenchRunConfig::initializeFromBson(const BSONObj& args) { initializeToDefaults(); + auto argToRegex = [](auto&& arg) { + return std::make_shared<pcre::Regex>(arg.regex(), + pcre_util::flagsToOptions(arg.regexFlags())); + }; + for (auto arg : args) { auto name = arg.fieldNameStringData(); if (name == "host") { @@ -750,25 +741,13 @@ void BenchRunConfig::initializeFromBson(const BSONObj& args) { } else if (name == "breakOnTrap") { breakOnTrap = arg.trueValue(); } else if (name == "trapPattern") { - const char* regex = arg.regex(); - const char* flags = arg.regexFlags(); - trapPattern = - std::shared_ptr<pcrecpp::RE>(new pcrecpp::RE(regex, flags2options(flags))); + trapPattern = argToRegex(arg); } else if (name == "noTrapPattern") { - const char* regex = arg.regex(); - const char* flags = arg.regexFlags(); - noTrapPattern = - std::shared_ptr<pcrecpp::RE>(new pcrecpp::RE(regex, flags2options(flags))); + noTrapPattern = argToRegex(arg); } else if (name == "watchPattern") { - const char* regex = arg.regex(); - const char* flags = arg.regexFlags(); - watchPattern = - std::shared_ptr<pcrecpp::RE>(new pcrecpp::RE(regex, flags2options(flags))); + watchPattern = argToRegex(arg); } else if (name == "noWatchPattern") { - const char* regex = arg.regex(); - const char* flags = arg.regexFlags(); - noWatchPattern = - std::shared_ptr<pcrecpp::RE>(new pcrecpp::RE(regex, flags2options(flags))); + noWatchPattern = argToRegex(arg); } else if (name == "ops") { // iterate through the objects in ops // create an BenchRunOp per @@ -946,10 +925,12 @@ void BenchRunWorker::generateLoadOnConnection(DBClientBase* conn) { op.executeOnce(conn, lsid, *_config, &opState); } catch (const DBException& ex) { if (!_config->hideErrors || op.showError) { - bool yesWatch = - (_config->watchPattern && _config->watchPattern->FullMatch(ex.what())); - bool noWatch = - (_config->noWatchPattern && _config->noWatchPattern->FullMatch(ex.what())); + bool yesWatch = (_config->watchPattern && + _config->watchPattern->matchView( + ex.what(), pcre::ANCHORED | pcre::ENDANCHORED)); + bool noWatch = (_config->noWatchPattern && + _config->noWatchPattern->matchView( + ex.what(), pcre::ANCHORED | pcre::ENDANCHORED)); if ((!_config->watchPattern && _config->noWatchPattern && !noWatch) || // If we're just ignoring things @@ -962,9 +943,12 @@ void BenchRunWorker::generateLoadOnConnection(DBClientBase* conn) { "error"_attr = causedBy(ex)); } - bool yesTrap = (_config->trapPattern && _config->trapPattern->FullMatch(ex.what())); - bool noTrap = - (_config->noTrapPattern && _config->noTrapPattern->FullMatch(ex.what())); + bool yesTrap = (_config->trapPattern && + _config->trapPattern->matchView( + ex.what(), pcre::ANCHORED | pcre::ENDANCHORED)); + bool noTrap = (_config->noTrapPattern && + _config->noTrapPattern->matchView( + ex.what(), pcre::ANCHORED | pcre::ENDANCHORED)); if ((!_config->trapPattern && _config->noTrapPattern && !noTrap) || (!_config->noTrapPattern && _config->trapPattern && yesTrap) || diff --git a/src/mongo/shell/bench.h b/src/mongo/shell/bench.h index a7d1f70c0ed..90831a8ab53 100644 --- a/src/mongo/shell/bench.h +++ b/src/mongo/shell/bench.h @@ -40,12 +40,9 @@ #include "mongo/platform/mutex.h" #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/thread.h" +#include "mongo/util/pcre.h" #include "mongo/util/timer.h" -namespace pcrecpp { -class RE; -} // namespace pcrecpp - namespace mongo { enum class OpType { @@ -238,10 +235,10 @@ public: bool handleErrors; bool hideErrors; - std::shared_ptr<pcrecpp::RE> trapPattern; - std::shared_ptr<pcrecpp::RE> noTrapPattern; - std::shared_ptr<pcrecpp::RE> watchPattern; - std::shared_ptr<pcrecpp::RE> noWatchPattern; + std::shared_ptr<pcre::Regex> trapPattern; + std::shared_ptr<pcre::Regex> noTrapPattern; + std::shared_ptr<pcre::Regex> watchPattern; + std::shared_ptr<pcre::Regex> noWatchPattern; /** * Operation description. A list of BenchRunOps, each describing a single diff --git a/src/mongo/shell/mongo_main.cpp b/src/mongo/shell/mongo_main.cpp index dd9231caa27..51ccb760ee7 100644 --- a/src/mongo/shell/mongo_main.cpp +++ b/src/mongo/shell/mongo_main.cpp @@ -39,7 +39,6 @@ #include <boost/log/sinks.hpp> #include <fstream> #include <iostream> -#include <pcrecpp.h> #include <signal.h> #include <stdio.h> #include <string.h> @@ -79,6 +78,7 @@ #include "mongo/util/net/ocsp/ocsp_manager.h" #include "mongo/util/net/ssl_options.h" #include "mongo/util/password.h" +#include "mongo/util/pcre.h" #include "mongo/util/quick_exit.h" #include "mongo/util/scopeguard.h" #include "mongo/util/signal_handlers.h" @@ -278,16 +278,16 @@ void shellHistoryAdd(const char* line) { // be able to add things like `.author`, so be smart about how this is // detected by using regular expresions. This is so we can avoid storing passwords // in the history file in plaintext. - static pcrecpp::RE hiddenHelpers( + static pcre::Regex hiddenHelpers( "\\.\\s*(auth|createUser|updateUser|changeUserPassword)\\s*\\("); // Also don't want the raw user management commands to show in the shell when run directly // via runCommand. - static pcrecpp::RE hiddenCommands( + static pcre::Regex hiddenCommands( "(run|admin)Command\\s*\\(\\s*{\\s*(createUser|updateUser)\\s*:"); - static pcrecpp::RE hiddenFLEConstructor(".*Mongo\\(([\\s\\S]*)secretAccessKey([\\s\\S]*)"); - if (!hiddenHelpers.PartialMatch(line) && !hiddenCommands.PartialMatch(line) && - !hiddenFLEConstructor.PartialMatch(line)) { + static pcre::Regex hiddenFLEConstructor(".*Mongo\\(([\\s\\S]*)secretAccessKey([\\s\\S]*)"); + if (!hiddenHelpers.matchView(line) && !hiddenCommands.matchView(line) && + !hiddenFLEConstructor.matchView(line)) { linenoiseHistoryAdd(line); } } |