Skip to content
Snippets Groups Projects
Commit 53c130b8 authored by mattijs's avatar mattijs
Browse files

ENH: dictionary: do not allow empty variables

parent 302643fb
Branches
Tags
No related merge requests found
......@@ -117,11 +117,12 @@ bool Foam::entry::New(dictionary& parentDict, Istream& is)
if (keyword.size() > 2 && keyword[1] == token::BEGIN_BLOCK)
{
// Recursive substitution mode. Replace between {} with
// expansion.
// expansion and then let standard variable expansion deal
// with rest.
string s(keyword(2, keyword.size()-3));
// Substitute dictionary and environment variables. Allow
// Substitute dictionary and environment variables. Do not allow
// empty substitutions.
stringOps::inplaceExpand(s, parentDict, true, true);
stringOps::inplaceExpand(s, parentDict, true, false);
keyword.std::string::replace(1, keyword.size()-1, s);
}
parentDict.substituteScopedKeyword(keyword);
......
......@@ -47,13 +47,11 @@ bool Foam::primitiveEntry::expandVariable
{
if (w.size() > 2 && w[0] == '$' && w[1] == token::BEGIN_BLOCK)
{
// Recursive substitution mode. Replace between {} with
// expansion.
// Recursive substitution mode. Replace between {} with expansion.
string s(w(2, w.size()-3));
// Substitute dictionary and environment variables. Allow
// Substitute dictionary and environment variables. Do not allow
// empty substitutions.
stringOps::inplaceExpand(s, dict, true, true);
stringOps::inplaceExpand(s, dict, true, false);
string newW(w);
newW.std::string::replace(1, newW.size()-1, s);
......@@ -83,6 +81,15 @@ bool Foam::primitiveEntry::expandVariable
if (envStr.empty())
{
FatalIOErrorIn
(
"primitiveEntry::expandVariable"
"(const string&, const dictionary&",
dict
) << "Illegal dictionary entry or environment variable name "
<< varName << endl << "Valid dictionary entries are "
<< dict.toc() << exit(FatalIOError);
return false;
}
append(tokenList(IStringStream('(' + envStr + ')')()));
......
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