Skip to content

Commit

Permalink
RepoVarExpand: Fix expansion of embedded words with invalid variable …
Browse files Browse the repository at this point in the history
…definitions

An incomplete variable definition is to be expanded literally. It should
produce the same result as if the the introducing '$' was escaped.
  • Loading branch information
mlandres committed Dec 15, 2023
1 parent 9d4853e commit 9ce8905
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/repo/RepoVariables_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(RepVarExpand)
RepVarExpandTest( "$_A_B:" , "$_A_B:" , "[_A_B]:" );
RepVarExpandTest( "${C:+a$Bba\\}" , "${C:+a$Bba\\}" , "${C:+a[Bba]\\}" );
RepVarExpandTest( "${C:+a$Bba}" , "" , "a[Bba]" );
RepVarExpandTest( "${C:+a${B\\}ba}" , "${C:+a${B\\}ba}" , "${C:+a${B\\}ba}" );
RepVarExpandTest( "${C:+a${B\\}ba}" , "" , "a${B}ba" );
RepVarExpandTest( "${C:+a${B}ba}" , "" , "a[B]ba" );
RepVarExpandTest( "${C:+a\\$Bba}" , "" , "a$Bba" );
RepVarExpandTest( "${C:+a\\${B\\}ba}" , "" , "a${B}ba" );
Expand Down
6 changes: 4 additions & 2 deletions zypp/repo/RepoVariables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ namespace zypp
else if ( *scan == '$' )
{
// an embedded var?
if ( ! (scan = findVarEnd( scan )) )
return false;
if ( const char * scanEnd = findVarEnd( scan ) )
scan = scanEnd;
else
++scan; // no valid var: treated as literal
}
else if ( *scan == '}' )
{
Expand Down

0 comments on commit 9ce8905

Please sign in to comment.