Merge pull request #1039 from atgeirr/replace-backslash-include

Replace backslash in INCLUDE paths
This commit is contained in:
Joakim Hove 2017-02-13 13:35:00 +01:00 committed by GitHub
commit c410f99625
4 changed files with 28 additions and 1 deletions

View File

@ -372,6 +372,13 @@ boost::filesystem::path ParserState::getIncludeFilePath( std::string path ) cons
boost::replace_all(path, pathKeywordPrefix + stringToFind, stringToReplace);
}
// Check if there are any backslashes in the path...
if (path.find('\\') != std::string::npos) {
// ... if so, replace with slashes and create a warning.
std::replace(path.begin(), path.end(), '\\', '/');
deck.getMessageContainer().warning("Replaced one or more backslash with a slash in an INCLUDE path.");
}
boost::filesystem::path includeFilePath(path);
if (includeFilePath.is_relative())

View File

@ -288,10 +288,20 @@ BOOST_AUTO_TEST_CASE( PATHS_has_global_scope ) {
ParseContext parseContext;
parseContext.update( ParseContext::PARSE_MISSING_INCLUDE , Opm::InputError::THROW_EXCEPTION);
parser.parseFile( "testdata/parser/PATHSInInclude.data", parseContext );
const auto deck = parser.parseFile( "testdata/parser/PATHSInInclude.data", parseContext );
BOOST_CHECK(deck.hasKeyword("OIL"));
BOOST_CHECK_THROW( parser.parseFile( "testdata/parser/PATHSInIncludeInvalid.data", ParseContext() ), std::invalid_argument );
}
BOOST_AUTO_TEST_CASE( PATHS_with_backslashes ) {
Parser parser;
ParseContext parseContext;
parseContext.update( ParseContext::PARSE_MISSING_INCLUDE , Opm::InputError::THROW_EXCEPTION);
const auto deck = parser.parseFile( "testdata/parser/PATHSWithBackslashes.data", parseContext );
BOOST_CHECK(deck.hasKeyword("OIL"));
}
BOOST_AUTO_TEST_CASE( handle_empty_title ) {
const auto* input_deck = "RUNSPEC\n\n"
"TITLE\n\n"

View File

@ -0,0 +1,7 @@
INCLUDE
'include\foobackslash.inc'
/
INCLUDE
'$FOOPATH\foo_target.inc'
/

View File

@ -0,0 +1,3 @@
PATHS
'FOOPATH' 'include\foopath' /
/