Skip to content

Support BOM removal #3

@judgej

Description

@judgej

This is a bit messy. The JSON response from Authorize.Net includes a BOM sequence at the start. This is invisible to the human eye, but causes json_decode() to throw a wobbly. It simply cannot decode the JSON with the BOM.

This is suggested in many places to remove the BOM:

preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $json_string);

I would probably be a little more specific by looking at only the first (up to) three characters:

preg_replace('/^[\x00-\x1F\x80-\xFF]{1,3}/', '', $json_string);

There is also a plugin for Guzzle that removes the BOM, but that appears to be for older Guzzle versions. Not sure about the latest.

Anyway, it has not really got anything to do with these messages, because it's not a part of the data, but if we are not aware of it, it will certainly come to bite us when not dealt with at the transport level.

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