Missed tagging a commented out test for edwinwu, and cleaned up some minor problems with the filename/path validator.

PiperOrigin-RevId: 416134225
This commit is contained in:
jfcarroll
2021-12-13 14:24:45 -08:00
committed by Copybara-Service
parent 5107a030fd
commit c77356eb92
4 changed files with 17 additions and 16 deletions
+10 -10
View File
@@ -24,12 +24,12 @@ namespace location {
namespace nearby {
namespace connections {
namespace parser {
bool Validate(std::string toBeValidated,
std::vector<std::string> illegalPatterns) {
return !std::any_of(illegalPatterns.begin(), illegalPatterns.end(),
[&toBeValidated](const auto& s) {
return toBeValidated.find(s) != std::string::npos;
});
bool HasIllegalCharacters(std::string toBeValidated,
std::vector<std::string> illegalPatterns) {
return std::any_of(illegalPatterns.begin(), illegalPatterns.end(),
[&toBeValidated](const auto& s) {
return toBeValidated.find(s) != std::string::npos;
});
}
namespace {
@@ -132,15 +132,15 @@ Exception EnsureValidPayloadTransferFrame(const PayloadTransferFrame& frame) {
frame.payload_header().type() ==
PayloadTransferFrame::PayloadHeader::FILE) {
if (frame.payload_header().has_file_name()) {
if (!Validate(frame.payload_header().file_name(),
ILLEGAL_FILENAME_PATTERNS)) {
if (HasIllegalCharacters(frame.payload_header().file_name(),
ILLEGAL_FILENAME_PATTERNS)) {
return {Exception::kFailed};
}
}
if (frame.payload_header().has_parent_folder()) {
if (!Validate(frame.payload_header().file_name(),
ILLEGAL_PARENT_FOLDER_PATTERNS)) {
if (HasIllegalCharacters(frame.payload_header().file_name(),
ILLEGAL_PARENT_FOLDER_PATTERNS)) {
return {Exception::kFailed};
}
}
+2 -2
View File
@@ -33,8 +33,8 @@ const std::vector<std::string> ILLEGAL_PARENT_FOLDER_PATTERNS{
Exception EnsureValidOfflineFrame(const OfflineFrame& offline_frame);
bool Validate(std::string toBeValidated,
std::vector<std::string> illegalPatterns);
bool HasIllegalCharacters(std::string toBeValidated,
std::vector<std::string> illegalPatterns);
} // namespace parser
} // namespace connections