Commit c8cde1f4 authored by Rémi Cresson's avatar Rémi Cresson
Browse files

Merge branch '2312-http_misinterpreted_as_extfilenameopts' into 'develop'

Robust extended filename options interpretation

Closes #2312

See merge request orfeotoolbox/otb!938
parents dae1d4d0 37cf0f8b
Pipeline #11740 passed with stage
in 24 minutes and 59 seconds
......@@ -67,7 +67,7 @@ otb_add_test(NAME TvOGRExtendedFilename
otb_add_test(NAME TvOGRExtendedFilenameGDALCreate
COMMAND otbOGRTestDriver
otbOGRExtendedFileNameGDALCreate
${TEMP}/test_OGRExtendedFilenameGDALCreate.shp?gdal:co:creationOption=OPTION
${TEMP}/test_OGRExtendedFilenameGDALCreate.shp?&gdal:co:creationOption=OPTION
)
otb_add_test(NAME TvOGRExtendedFilenameGDALLayer
......
......@@ -53,7 +53,7 @@ if(OTB_DATA_USE_LARGEINPUT)
otb_test_application(NAME apTvRaSARCalibration_SENTINEL1_PRODUCT_INPUT
APP SARCalibration
OPTIONS -in LARGEINPUT{SENTINEL1/S1A_S6_SLC__1SSV_20150619T195043/measurement/s1a-s6-slc-vv-20150619t195043-20150619t195101-006447-00887d-001.tiff}
-out "${TEMP}/apTvRaSarRadiometricCalibration_SENTINEL1_PRODUCT_INPUT.tif?box=1200:1100:256:256"
-out "${TEMP}/apTvRaSarRadiometricCalibration_SENTINEL1_PRODUCT_INPUT.tif?&box=1200:1100:256:256"
VALID --compare-image ${NOTOL}
${BASELINE}/raTvSarRadiometricCalibration_SENTINEL1_PRODUCT_INPUT.tif
${TEMP}/apTvRaSarRadiometricCalibration_SENTINEL1_PRODUCT_INPUT.tif )
......
......@@ -44,35 +44,44 @@ void ExtendedFilenameHelper::SetExtendedFileName(const std::string& extFname)
{
this->m_ExtendedFileName = extFname;
this->m_OptionMap.clear();
std::vector<std::string> tmp1;
std::vector<std::string> tmp2;
std::vector<std::string> splits;
if (!m_ExtendedFileName.empty())
{
boost::split(tmp1, m_ExtendedFileName, boost::is_any_of("?"), boost::token_compress_on);
this->SetSimpleFileName(tmp1[0]);
if (tmp1.size() > 1)
// We consider that everything before the last occurrence of "?&" is
// the file path, and everything after (if any) are the extended
// filename options. This is more secure than considering only "?" since
// the path can be a vsicurl URI containing some "?" chars, and the
// documentation clearly states that the right pattern for extended
// filenames is "file.tif?&key1=value1&...&keyN=valueN".
auto locator = m_ExtendedFileName.rfind("?&");
auto fileName = m_ExtendedFileName.substr(0, locator);
this->SetSimpleFileName(fileName);
if (locator != std::string::npos)
{
boost::split(tmp2, tmp1[1], boost::is_any_of("&"), boost::token_compress_on);
for (unsigned int i = 0; i < tmp2.size(); i++)
if (!tmp2[i].empty())
auto extension = m_ExtendedFileName.substr(locator + 1);
boost::split(splits, extension, boost::is_any_of("&"), boost::token_compress_on);
for (const auto& split: splits)
if (!split.empty())
{
std::vector<std::string> tmp;
boost::split(tmp, tmp2[i], boost::is_any_of("="), boost::token_compress_on);
boost::split(tmp, split, boost::is_any_of("="), boost::token_compress_on);
if (tmp.size() > 1)
{
if (!tmp[1].empty())
auto key = tmp[0];
auto value = tmp[1];
if (!value.empty())
{
if (m_OptionMap[tmp[0]].empty())
if (m_OptionMap[key].empty())
{
m_OptionMap[tmp[0]] = tmp[1];
m_OptionMap[key] = value;
}
else
{
itkWarningMacro("Duplicated option detected: " << tmp[0] << ". Using value " << tmp[1] << ".");
itkWarningMacro("Duplicated option detected: " << key << ". Using value " << value << ".");
}
}
else
itkGenericExceptionMacro(<< "Value for option '" << tmp[0] << "' is not set.");
itkGenericExceptionMacro(<< "Value for option '" << key << "' is not set.");
}
}
}
......
......@@ -406,7 +406,7 @@ if(OTB_DATA_USE_LARGEINPUT)
--compare-image ${EPSILON_9} ${BASELINE}/ioTvJP22TIF_Extract_${current_type}_res5.tif
${TEMP}/ioTvJP22TIF_Extract_${current_type}_res5_OUT.tif
otbMultiChannelExtractROI
-ushort ${current_file}?resol=5
-ushort ${current_file}?&resol=5
-ushort ${TEMP}/ioTvJP22TIF_Extract_${current_type}_res5_OUT.tif?&box=0:0:128:128
-channels 1
-time
......
......@@ -27,37 +27,16 @@ namespace otb
ExtendedFilenameToReaderOptions::ExtendedFilenameToReaderOptions() : ExtendedFilenameHelper()
{
m_Options.simpleFileName.first = false;
m_Options.simpleFileName.second = "";
m_Options.simpleFileName = {false, ""};
m_Options.extGEOMFileName = {false, ""};
m_Options.subDatasetIndex = {false, 0};
m_Options.resolutionFactor = {false, 0};
m_Options.skipCarto = {false, false};
m_Options.skipGeom = {false, false};
m_Options.skipRpcTag = {false, false};
m_Options.bandRange = {false, ""};
m_Options.extGEOMFileName.first = false;
m_Options.extGEOMFileName.second = "";
m_Options.subDatasetIndex.first = false;
m_Options.subDatasetIndex.second = 0;
m_Options.resolutionFactor.first = false;
m_Options.resolutionFactor.second = 0;
m_Options.skipCarto.first = false;
m_Options.skipCarto.second = false;
m_Options.skipGeom.first = false;
m_Options.skipGeom.second = false;
m_Options.skipRpcTag.first = false;
m_Options.skipRpcTag.second = false;
m_Options.bandRange.first = false;
m_Options.bandRange.second = "";
m_Options.optionList.push_back("geom");
m_Options.optionList.push_back("sdataidx");
m_Options.optionList.push_back("resol");
m_Options.optionList.push_back("skipcarto");
m_Options.optionList.push_back("skipgeom");
m_Options.optionList.push_back("skiprpctag");
m_Options.optionList.push_back("bands");
m_Options.optionList = {"geom", "sdataidx", "resol", "skipcarto", "skipgeom", "skiprpctag", "bands"};
}
void ExtendedFilenameToReaderOptions::SetExtendedFileName(const char* extFname)
......@@ -78,18 +57,15 @@ void ExtendedFilenameToReaderOptions::SetExtendedFileName(const std::string& ext
if (!map["geom"].empty())
{
m_Options.extGEOMFileName.first = true;
m_Options.extGEOMFileName.second = map["geom"];
m_Options.extGEOMFileName = {true, map["geom"]};
}
if (!map["sdataidx"].empty())
{
m_Options.subDatasetIndex.first = true;
m_Options.subDatasetIndex.second = atoi(map["sdataidx"].c_str());
m_Options.subDatasetIndex = {true, std::stoi(map["sdataidx"])};
}
if (!map["resol"].empty())
{
m_Options.resolutionFactor.first = true;
m_Options.resolutionFactor.second = atoi(map["resol"].c_str());
m_Options.resolutionFactor = {true, std::stoi(map["resol"])};
}
if (!map["skipcarto"].empty())
......@@ -129,8 +105,7 @@ void ExtendedFilenameToReaderOptions::SetExtendedFileName(const std::string& ext
reg.compile("^((\\-?[0-9]+)?(:(\\-?[0-9]+)?)?)(,(\\-?[0-9]+)?(:(\\-?[0-9]+)?)?)*$");
if (reg.find(map["bands"]))
{
m_Options.bandRange.first = true;
m_Options.bandRange.second = map["bands"];
m_Options.bandRange = {true, map["bands"]};
}
else
{
......
......@@ -77,7 +77,7 @@ otb_add_test(NAME ioTvExtendedFilenameToReaderOptions_BandList COMMAND otbExtend
${BASELINE}/ioTvExtendedFilenameToReaderOptions_BandList.txt
${TEMP}/ioTvExtendedFilenameToReaderOptions_BandList.txt
otbExtendedFilenameToReaderOptions
/home/data/filename.tif?bands=3,5:,-3,2:-2
/home/data/filename.tif?&bands=3,5:,-3,2:-2
${TEMP}/ioTvExtendedFilenameToReaderOptions_BandList.txt
6
)
......@@ -175,5 +175,5 @@ otb_add_test(NAME ioTvImageFileReaderExtendedFileName_SkipPR COMMAND otbExtended
otb_add_test(NAME ioTvImageFileWriterExtendedFileName_NODATA COMMAND otbExtendedFilenameTestDriver
otbImageFileWriterWithExtendedFilename
${INPUTDATA}/ToulouseExtract_WithGeom.tif
${TEMP}/ioImageFileWriterExtendedFileName_NODATA.tif?nodata=1:-99999,2:-88888
${TEMP}/ioImageFileWriterExtendedFileName_NODATA.tif?&nodata=1:-99999,2:-88888
)
......@@ -916,7 +916,7 @@ otb_add_test(NAME ioTvImageFileWriterTIF2TIF COMMAND otbImageIOTestDriver
${TEMP}/ioImageFileWriterTIF2TIF_QB_Toulouse_Ortho_PAN.tif
otbImageFileWriterTest
${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif
${TEMP}/ioImageFileWriterTIF2TIF_QB_Toulouse_Ortho_PAN.tif?epsg=4326 )
${TEMP}/ioImageFileWriterTIF2TIF_QB_Toulouse_Ortho_PAN.tif?&epsg=4326 )
otb_add_test(NAME ioTvCompareWritingComplexImage_TIF COMMAND otbImageIOTestDriver
otbCompareWritingComplexImageTest
......@@ -1222,7 +1222,7 @@ otb_add_test(NAME ioTvImageIOToReaderOptions_OptBandTest COMMAND otbImageIOTestD
--compare-image ${EPSILON_9} ${BASELINE}/QB_Toulouse_Ortho_XS_OptBand2to4.tif
${TEMP}/QB_Toulouse_Ortho_XS_OptBand2to4.tif
otbImageFileReaderOptBandTest
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif?bands=2:4
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif?&bands=2:4
${TEMP}/QB_Toulouse_Ortho_XS_OptBand2to4.tif
4
)
......@@ -1231,7 +1231,7 @@ otb_add_test(NAME ioTvImageIOToReaderOptions_OptBandReorgTest COMMAND otbImageIO
--compare-image ${EPSILON_9} ${BASELINE}/QB_Toulouse_Ortho_XS_OptBandReorg.tif
${TEMP}/QB_Toulouse_Ortho_XS_OptBandReorg.tif
otbImageFileReaderOptBandTest
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif?bands=2,:,-3,2:-1
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif?&bands=2,:,-3,2:-1
${TEMP}/QB_Toulouse_Ortho_XS_OptBandReorg.tif
4
)
......@@ -1241,7 +1241,7 @@ otb_add_test(NAME ioTvImageIOToWriterOptions_OptBandTest COMMAND otbImageIOTestD
${TEMP}/QB_Toulouse_Ortho_XS_WriterOptBand2to4.tif
otbImageFileWriterOptBandTest
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif
${TEMP}/QB_Toulouse_Ortho_XS_WriterOptBand2to4.tif?bands=2:4
${TEMP}/QB_Toulouse_Ortho_XS_WriterOptBand2to4.tif?&bands=2:4
4
)
......@@ -1250,7 +1250,7 @@ otb_add_test(NAME ioTvImageIOToWriterOptions_OptBandReorgTest COMMAND otbImageIO
${TEMP}/QB_Toulouse_Ortho_XS_WriterOptBandReorg.tif
otbImageFileWriterOptBandTest
${INPUTDATA}/QB_Toulouse_Ortho_XS.tif
${TEMP}/QB_Toulouse_Ortho_XS_WriterOptBandReorg.tif?bands=2,:,-3,2:-1
${TEMP}/QB_Toulouse_Ortho_XS_WriterOptBandReorg.tif?&bands=2,:,-3,2:-1
4
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment