Skip to content

Commit

Permalink
FileFormatSpi1D: Handle "Version1" corner case
Browse files Browse the repository at this point in the history
Signed-off-by: Marian Beermann <public@enkore.de>
  • Loading branch information
enkore committed Aug 7, 2020
1 parent fb136ae commit 9ef151a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/OpenColorIO/fileformats/FileFormatSpi1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ CachedFileRcPtr LocalFileFormat::read(

if(chunks[0] == "Version")
{
// " " in format means any number of spaces (white space,
// new line, tab) including 0 of them.
// "Version1" is valid.
if (chunks.size() != 2 || !StringToInt(&version, chunks[1].c_str()))
{
ThrowErrorMessage("Invalid 'Version' Tag", currentLine, headerLine);
Expand All @@ -128,6 +125,11 @@ CachedFileRcPtr LocalFileFormat::read(
ThrowErrorMessage("Only format version 1 supported", currentLine, headerLine);
}
}
else if(chunks[0] == "Version1")
{
// "Version1" is valid.
version = 1;
}
else if(chunks[0] == "From")
{
if (chunks.size() != 3 || !StringToFloat(&from_min, chunks[1].c_str())
Expand Down
16 changes: 16 additions & 0 deletions tests/cpu/fileformats/FileFormatSpi1D_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ OCIO::LocalCachedFileRcPtr ReadSpi1d(const std::string & fileContent)
return OCIO::DynamicPtrCast<OCIO::LocalCachedFile>(cachedFile);
}

OCIO_ADD_TEST(FileFormatSpi1D, read_version_corner_case)
{
const std::string SAMPLE_NO_ERROR =
"Version1\n"
"From 0.0 1.0\n"
"Length 2\n"
"Components 1\n"
"{\n"
"0.0\n"
"\n"
"1.0\n"
"}\n";

OCIO_CHECK_NO_THROW(ReadSpi1d(SAMPLE_NO_ERROR));
}

OCIO_ADD_TEST(FileFormatSpi1D, read_failure)
{
{
Expand Down

0 comments on commit 9ef151a

Please sign in to comment.