Skip to content

[inline TODO] serving non-utf8 content as utf8 in /rpc/TXP_RPCServer.php #1052

@petecooper

Description

@petecooper

Background
This issue is part of a project (#1004) to migrate inline TODOs to GitHub issues. If this issue is still relevant, please assign milestone(s) and team member(s) accordingly.

On acceptance as a valid issue, the code should be annotated with a comment pointing back to this issue.

On completion of the issue, the code should be updated to remove the comment and the pointer to the issue.

TODO and surrounding code
https://github.com/textpattern/textpattern/blob/dev/rpc/TXP_RPCServer.php#L307

    // Override default UTF-8 output, if needed.
    function output($xml, $enc = 'utf-8')
    {
        // Be kind with non-UTF-8 capable clients.
        if ($enc != 'utf-8') {
            if ($enc == 'iso-8859-1' && function_exists('utf8_decode') && is_callable('utf8_decode')) {
                $xml = utf8_decode($xml);
            } elseif (function_exists('mb_convert_encoding') && is_callable('mb_convert_encoding')) {
                $xml = mb_convert_encoding($xml, $enc, 'utf-8');
            } else {
                // TODO: shouldn't this throw an error instead of serving non-UTF-8 content as UTF-8?
                // If no decoding possible, serve contents as UTF-8.
                $enc = 'utf-8';
            }
        }
        $xml = '<?xml version="1.0" encoding="'.$enc.'" ?>'.n.$xml;
        $length = strlen($xml);
        header('Connection: close');
        header('Content-Length: '.$length);
        header('Content-Type: text/xml charset='.$enc);
        header('Date: '.date('r'));
        echo $xml;
        exit;
    }
//------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions