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

An error is thrown if a file contains non UTF-8 characters #8

Closed
matjazpotocnik opened this issue Mar 23, 2019 · 7 comments
Closed

Comments

@matjazpotocnik
Copy link

File and directory names on Windows might not be UTF-8 encoded and json_encode() fails. This is what I have come up with (around line 100):

    $encoded = json_encode($response);
    if(!$encoded) {
        //replace "unknown" charaters with ?
        $i = 0;
        foreach($response['stdout'] as $v) {
            $response['stdout'][$i] = preg_replace('/[\x00-\x1F\x80-\xFF]/', '?', $v);
            $i++;
        }
      $encoded = json_encode($response);
    }

    header("Content-Type: application/json");
    echo $encoded;
    die();
@flozz
Copy link
Owner

flozz commented Feb 2, 2021

Do not hesitate to make a PR to fix the encoding on Windows :)

@cli-ish
Copy link

cli-ish commented May 11, 2023

A possible workaround to this problem would be to encode the stdout result with base64 or hex to ensure that no invalid characters are encoded with json. The client side would have to decode the json field stdout with base64 or hex and could then output it again. The same procedure is already performed with the files.

@cli-ish
Copy link

cli-ish commented May 22, 2023

@flozz Would this be a desired function as I described?

@flozz
Copy link
Owner

flozz commented May 23, 2023

Yeah probably encoding stdout/stderr to base64 could save us here... Do you think paths (cwd) should be encoded too? :)

@cli-ish
Copy link

cli-ish commented May 25, 2023

Not sure, could be a potential problem. Would this be worth a PR from my side?

@flozz
Copy link
Owner

flozz commented May 26, 2023

Yes please make a PR if you want to implement a fix for this issue :)

@flozz
Copy link
Owner

flozz commented May 28, 2023

Fix released in v2023.05.28 thanks to @cli-ish :)

@flozz flozz closed this as completed May 28, 2023
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

3 participants