@@ -913,6 +913,7 @@ private function resolveTestVariable($inputString, $args)
913
913
*/
914
914
private function replaceMatchesIntoArg ($ matches , &$ outputArg , $ delimiter )
915
915
{
916
+ $ matches = array_unique ($ matches );
916
917
foreach ($ matches as $ match ) {
917
918
$ replacement = null ;
918
919
$ variable = $ this ->stripAndSplitReference ($ match , $ delimiter );
@@ -953,22 +954,24 @@ private function processQuoteBreaks($match, $argument, $replacement)
953
954
$ quoteBefore = true ;
954
955
$ quoteAfter = true ;
955
956
956
- // Prepare replacement with quote breaks if needed
957
- if ($ argument [$ beforeIndex ] != "\"" ) {
958
- $ replacement = '" . ' . $ replacement ;
957
+ // Determine if there is a Single quote before/after the $match, and if there is only 1 quote before/after.
958
+ if ($ argument [$ beforeIndex ] != '" ' || substr_count ($ argument , '" ' , 0 , $ beforeIndex +1 )>1 ) {
959
959
$ quoteBefore = false ;
960
960
}
961
- if ($ argument [$ afterIndex ] != "\"" ) {
962
- $ replacement = $ replacement . ' . " ' ;
961
+ if ($ argument [$ afterIndex ] != '" ' || substr_count ($ argument , '" ' , $ afterIndex )>1 ) {
963
962
$ quoteAfter = false ;
964
963
}
965
- //Remove quotes at either end of argument if they aren't necessary.
964
+ //Remove quotes at either end of argument if they aren't necessary. Add quote breaking if needed
966
965
if ($ quoteBefore ) {
967
966
$ outputArg = substr ($ outputArg , 0 , $ beforeIndex ) . substr ($ outputArg , $ beforeIndex +1 );
968
967
$ afterIndex --;
968
+ } else {
969
+ $ replacement = '" . ' . $ replacement ;
969
970
}
970
971
if ($ quoteAfter ) {
971
972
$ outputArg = substr ($ outputArg , 0 , $ afterIndex ) . substr ($ outputArg , $ afterIndex +1 );
973
+ } else {
974
+ $ replacement = $ replacement . ' . " ' ;
972
975
}
973
976
$ outputArg = str_replace ($ match , $ replacement , $ outputArg );
974
977
return $ outputArg ;
0 commit comments