Skip to content

Encoding Issues on getResponse() #246

Description

@bgrou

Hello there, I am having problems with encoding on a project that before used SphinxQL Library.
My database is in latin1 and I can't change it.
The problem is here:

public function getResponse() {
		if (null === $this->response) {
			$this->response = json_decode($this->string, true);
			if (json_last_error() !== JSON_ERROR_NONE) {
				if (json_last_error() !== JSON_ERROR_UTF8 || !$this->stripBadUtf8()) {
					throw new RuntimeException('fatal error while trying to decode JSON response');
				}

				$this->response = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $this->string), true);
			}

			if (empty($this->response)) {
				$this->response = [];
			}
		}
		return $this->response;
	}

Does this package only support UTF-8? I don't want to use stripBadUtf8 flag since I will lose part of the info.
Currently I changed the getResponse() to detect the encoding and convert it and it's working.
I also think the thrown exception message should be more explicit since if I have an encoding error and if I didn't set the stripBadUTF8 flag, the error message is "fatal error while trying to decode JSON response".

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions