Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getOutput() does not trim the form feed character #61

Closed
daveherman71 opened this issue Apr 19, 2023 · 5 comments
Closed

getOutput() does not trim the form feed character #61

daveherman71 opened this issue Apr 19, 2023 · 5 comments

Comments

@daveherman71
Copy link

In the Windows environment it appears that the stdOut is preceded by \x0C (ASCII Form Feed character).

This is a problem when the expected stdOut is a JSON response string which will not parse using json_decode() because of the "invisible" form feed character.

The PHP trim() function does not strip these characters by default so the suggested change would be to replace the getOutput() function as follows

    public function getOutput($trim = true)
    {
        return $trim ? trim($this->_stdOut, " \t\n\r\0\x0B\x0C") : $this->_stdOut;
    }

And perhaps extend this change to getError() and getStdErr() as well.

@mikehaertl
Copy link
Owner

What if these characters are part of some expected output? We should not just trim withouth warning. We could have an option (default off), though. But I wonder if it's really our library that should take care of this.

Did you maybe investigate what causes this extra character? Does it happen in both cases, with useExec = true/false?

@mikehaertl
Copy link
Owner

Sorry, I should have looked at your code more closely. I forgot that we already trim by default. So maybe it's really safe to add these extra characters. I'll have a look.

@mikehaertl
Copy link
Owner

@daveherman71 I've created a PR. Could you have a look and maybe also test if it works for you? I don't use Windows.

@daveherman71
Copy link
Author

Thanks, that version works.

Please note that this module was installed as a dependency of phpwkhtmltopdf - I did not install it myself.

mikehaertl added a commit that referenced this issue Apr 19, 2023
Issue #61 Add form feed to trimmed characters
@mikehaertl
Copy link
Owner

Please note that this module was installed as a dependency of phpwkhtmltopdf - I did not install it myself.

Hmm, ok, but with phpwkhtmltopdf there should be no problem with missing trim characters? So I assume you also use the library for other shell commands.

Anyway, I've just released 1.7.0 containing this fix. Thanks for your help.

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

No branches or pull requests

2 participants