P4Perl P4::MergeData::RunMergeTool, quote filename arguments to protect from shell metacharacters
Also Perforce internal job088679 has been logged against p4api.
Using P4Perl to do a merge that uses P4::MergeData::RunMergeTool to call out to a bash script as the merge tool.
On Linux, if filenames have the shell metacharacter "(" in their names it causes bash to fail with "h: -c: line 0: syntax error near unexpected token `(' "
Other shell metacharacters would likely cause issues as well. This is expected shell behaviour and you would normally either quote a filename that contains metacharacters or escape the metacharacters.
For "(" it works on windows as "(" isn't a windows cmd shell metacharacter.
Quoting the arguments passed from RunMergeTool should escape the special meaning of any shell metacharacters.
It doesn't seem to be a P4Perl problem directly; invoking P4::MergeData::RunMergeTool, the control is handed over to the native P4.so.
Somewhere in P4.so, there's probably a call like system("mergeTool BASE THEIRS YOURS MERGED").
Perhaps that could be adjusted to allow for special characters especially in the parameters.
[I reported this originally, and was involved in the investigation]
This doesn't seem like a P4Perl bug. The error is somewhere in the native P4 library against which P4Perl links (and to which include\p4\runcmd.h corresponds).
To add detail: I hit the problem with filenames containing "(" and ";", each failing differently, but the shell being the culprit in both cases. I didn't hit the problem with filenames containing whitespace because of the above ("UNIX: quote with ' args with spaces, and use system()").
I never hit the problem (with the same files) on Windows. I believe the reason is that the shell never gets involved via CreateProcess() - not that "(" isn't a Windows metacharacter. (";" definitely is a Windows CMD metacharacter and I never had issues with ";" either.)
Suggested solutions:
PROPOSAL 1: You already handle spaces as special ("UNIX: quote with ' args with spaces, and use system()"). Do the same with the other shell metacharacters. I.e. if the filename contains ";", it must be quoted too.
PROPOSAL 2: Use execve (or friends) instead of system. That allows you to specify the parameters as an array, and the shell doesn't get involved.
[I reported this originally, and was involved in the investigation]
This doesn't seem like a P4Perl bug. The error is somewhere in the native P4 library against which P4Perl links (and to which include\p4\runcmd.h corresponds).
To add detail: I hit the problem with filenames containing "(" and ";", each failing differently, but the shell being the culprit in both cases. I didn't hit the problem with filenames containing whitespace because of the above ("UNIX: quote with ' args with spaces, and use system()").
I never hit the problem (with the same files) on Windows. I believe the reason is that the shell never gets involved via CreateProcess() - not that "(" isn't a Windows metacharacter. (";" definitely is a Windows CMD metacharacter and I never had issues with ";" either.)
Suggested solutions:
PROPOSAL 1: You already handle spaces as special ("UNIX: quote with ' args with spaces, and use system()"). Do the same with the other shell metacharacters. I.e. if the filename contains ";", it must be quoted too.
PROPOSAL 2: Use execve (or friends) instead of system. That allows you to specify the parameters as an array, and the shell doesn't get involved.