Skip to content

Commit

Permalink
Merge pull request #807 from Expensify/master
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
rafecolton authored Jun 1, 2020
2 parents 2a271b8 + 0b996bc commit bda0750
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions BedrockPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ BedrockPlugin::~BedrockPlugin() {
}
}

bool BedrockPlugin::isValidDate(const string& date)
{
return SREMatch("^(19|2[0-9])\\d\\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])( \\d{2}:\\d{2}:\\d{2})?$", date);
}

void BedrockPlugin::verifyAttributeInt64(const SData& request, const string& name, size_t minSize) {
if (request[name].size() < minSize) {
STHROW("402 Missing " + name);
Expand Down Expand Up @@ -41,6 +46,17 @@ void BedrockPlugin::verifyAttributeBool(const SData& request, const string& name
}
}

void BedrockPlugin::verifyAttributeDate(const SData& request, const char* key, bool require)
{
if (require && request[key].empty()) {
STHROW("402 Missing " + string(key));
}

if (!request[key].empty() && !isValidDate(request[key])) {
STHROW("402 Malformed " + string(key));
}
}

STable BedrockPlugin::getInfo() {
return STable();
}
Expand Down
6 changes: 6 additions & 0 deletions BedrockPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ class BedrockPlugin {
static constexpr int64_t MAX_SIZE_BLOB = 1024 * 1024;
static constexpr int64_t MAX_SIZE_SMALL = 255;

/**
* Check if a date or datetime is valid
*/
static bool isValidDate(const string& date);

// Utility functions for verifying expected input.
static void verifyAttributeInt64(const SData& request, const string& name, size_t minSize);
static void verifyAttributeSize(const SData& request, const string& name, size_t minSize, size_t maxSize);
static void verifyAttributeBool(const SData& request, const string& name, bool require = true);
static void verifyAttributeDate(const SData& request, const char* key, bool require);

BedrockPlugin(BedrockServer& s);
virtual ~BedrockPlugin();
Expand Down

0 comments on commit bda0750

Please sign in to comment.