Skip to content

utf-8 is not handled correctly in readAsString and readAsJson #39

@DariuszOstolski

Description

@DariuszOstolski

It seems that readAsString method is not handling utf-8 characters that are out of ascii range correctly, for example: '°C' is interpreted as '°C'. I propose replacing implementation of readAsString:

readAsString: {
		value: function() {
			var buffer = this.buffer;
			var charCount = buffer.byteLength;
			var charSize = 1;
			var byteCount = charCount * charSize;
			var bufferView = new DataView(buffer);

			var charCodes = [];

			for (var i = 0; i < charCount; ++i) {
				var charCode = bufferView.getUint8(i * charSize, true);
				charCodes.push(charCode);
			}

			return (this._string = String.fromCharCode.apply(null, charCodes));
		}

method with following line:

readAsString: {
		value: function() {
			return new TextDecoder().decode(this.buffer);
		}

BR,
Dariusz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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