From cbb82a6a97062b47c7a482f50d221027576215e7 Mon Sep 17 00:00:00 2001 From: Vijay Vikram Singh Date: Thu, 9 Jan 2020 08:37:34 -0800 Subject: [PATCH] fix(ios): updated Ti.Blob.toString() behaviour to original (#11421) Fixes TIMOB-27350 --- .../ti.internal/extensions/ti/ti.blob.js | 3 +- tests/Resources/ti.blob.addontest.js | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/Resources/ti.blob.addontest.js diff --git a/common/Resources/ti.internal/extensions/ti/ti.blob.js b/common/Resources/ti.internal/extensions/ti/ti.blob.js index 865d33a0446..3489c70ca19 100644 --- a/common/Resources/ti.internal/extensions/ti/ti.blob.js +++ b/common/Resources/ti.internal/extensions/ti/ti.blob.js @@ -9,6 +9,7 @@ if (Ti.Platform.osname === 'iphone' || Ti.Platform.osname === 'ipad') { const buffer = Ti.createBuffer({ value: '' }); const blob = buffer.toBlob(); blob.constructor.prototype.toString = function () { - return this.text; + const value = this.text; + return (value === undefined) ? '[object TiBlob]' : value; }; } diff --git a/tests/Resources/ti.blob.addontest.js b/tests/Resources/ti.blob.addontest.js new file mode 100644 index 00000000000..0743d6edd5c --- /dev/null +++ b/tests/Resources/ti.blob.addontest.js @@ -0,0 +1,30 @@ +/* + * Appcelerator Titanium Mobile + * Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved. + * Licensed under the terms of the Apache Public License + * Please see the LICENSE included with this distribution for details. + */ +/* eslint-env mocha */ +/* eslint no-unused-expressions: "off" */ +'use strict'; +const should = require('./utilities/assertions'); + +describe('Titanium.Blob', function () { + describe('#toString()', function () { + it('binary content', function () { + const blob = Ti.Filesystem.getFile('SmallLogo.png').read(); + should(blob.toString()).eql('[object TiBlob]'); + }); + + it('empty string', function () { + const blob = Ti.createBuffer({ value: '' }).toBlob(); + should(blob.toString()).eql(''); + }); + + it('text content', function () { + const blob = Ti.createBuffer({ value: 'test toString()' }).toBlob(); + should(blob.toString()).eql('test toString()'); + }); + + }); +});