Skip to content

Commit

Permalink
Validate the Timestamp's YAML tags on parsing
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <[email protected]>
  • Loading branch information
Tempate committed Jan 22, 2024
1 parent ad60d90 commit 7749e79
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ddspipe_yaml/src/cpp/YamlReader_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <ddspipe_yaml/Yaml.hpp>
#include <ddspipe_yaml/YamlReader.hpp>
#include <ddspipe_yaml/YamlValidator.hpp>
#include <ddspipe_yaml/yaml_configuration_tags.hpp>

namespace eprosima {
Expand Down Expand Up @@ -291,12 +292,31 @@ std::string YamlReader::get<std::string>(
return get_scalar<std::string>(yml);
}

template <>
DDSPIPE_YAML_DllAPI
bool YamlValidator::validate<utils::Timestamp>(
const Yaml& yml,
const YamlReaderVersion& /* version */)
{
const std::set<TagType> tags{
TIMESTAMP_DATETIME_FORMAT_TAG,
TIMESTAMP_LOCAL_TAG,
TIMESTAMP_DATETIME_TAG,
TIMESTAMP_MILLISECONDS_TAG,
TIMESTAMP_MICROSECONDS_TAG,
TIMESTAMP_NANOSECONDS_TAG};

return YamlValidator::validate_tags(yml, tags);
}

template <>
DDSPIPE_YAML_DllAPI
utils::Timestamp YamlReader::get<utils::Timestamp>(
const Yaml& yml,
const YamlReaderVersion version /* version */)
{
YamlValidator::validate<utils::Timestamp>(yml, version);

utils::Timestamp ret_timestamp;
std::string datetime_str;
std::string datetime_format("%Y-%m-%d_%H-%M-%S");
Expand Down
2 changes: 2 additions & 0 deletions ddspipe_yaml/test/unittest/yaml_writer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(TEST_NAME YamlWriterTest)

set(TEST_SOURCES
${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp
${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp
${PROJECT_SOURCE_DIR}/src/cpp/YamlWriter.cpp
YamlWriterTest.cpp
)
Expand Down Expand Up @@ -61,6 +62,7 @@ set(TEST_NAME YamlWriter_collections_test)

set(TEST_SOURCES
${PROJECT_SOURCE_DIR}/src/cpp/YamlReader_generic.cpp
${PROJECT_SOURCE_DIR}/src/cpp/YamlValidator.cpp
${PROJECT_SOURCE_DIR}/src/cpp/YamlWriter.cpp
YamlWriter_collections_test.cpp
)
Expand Down

0 comments on commit 7749e79

Please sign in to comment.