Skip to content

Conversation

N1ebieski
Copy link
Contributor

@N1ebieski N1ebieski commented Mar 10, 2025

Fixes #271, #329

Probably fixes #458

If the contents of the file with the PHP code contains string with concatenation for example:

<?php

$className = "App\\DynamicApp\\Models\\" . ucfirst($relationshipField->attribute) . "Model";

then the command will look like this:

php-parser detect "<?php

\$className = \"App\\DynamicApp\\Models\\\\" . ucfirst(\$relationshipField->attribute) . \"Model\";"

There is one more backslash after "Models\\" than there should be. Then the command returns an error:

bash: syntax error near unexpected token ('`

I suggest to remove one backslash from replacements in the cleanArg function:

replacements.push([/\\"/g, '\\\"']);

because 2nd replacement in the line:

replacements.push([/\"/g, '\\"']);

duplicates backslashes in that case.

@joetannenbaum
Copy link
Collaborator

The problem is that this breaks something like the following:

$myName = "Joe \"Howdy\" Tannenbaum";

Searching out a more reliable (preferably built-in) argument escaping mechanism in Node that works well cross-platform.

…nto Fix-PHP-String-Concatenation-in-Output-Panel-Interpreted-as-Shell-Commands-#20
@N1ebieski
Copy link
Contributor Author

N1ebieski commented Apr 10, 2025

@joetannenbaum hmmm maybe just add a negative lookbehind and lookahead:

replacements.push([/(?<!\\)\\(?!\\)"/g, '\\\\"']);

Then only a single, unescaped \ backslash will be escaped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: "Syntax error near unexpected token" [Bug]: PHP String Concatenation in Output Panel Interpreted as Shell Commands

2 participants