This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Angular.copy() does not work properly for generic ArrayBuffer type. #12680
Closed
Description
When trying to copy an existing ArrayBuffer without using any specific view, angular.copy returns an empty / unusable object.
var genericArray = new ArrayBuffer(512); // ArrayBuffer {byteLength:512}
var copyArray = angular.copy(genericArray); // Wrong - Object{}
var subArray = genericArray.slice(0); // Correct - ArrayBuffer{byteLength:512}
( JSFiddle to test )
I think either angular.copy should use ArrayBuffer.prototype.slice() (Polyfills are available for old browsers) or, at least, throw a warning to the user indicating that an ArrayBufferView must be used.
It can leads to misunderstanding of some "simple" pieces of code.
// Following HTTP mock will return incorrect value because of angular.copy.
$httpBackend.whenGET(/.*/).respond(
function() {
var zip = new JSZip();
zip.file("nested/hello.txt", "Hello World\n");
var archive = zip.generate({type:"arraybuffer"});
return [200, archive, {
'Content-Type': 'application/zip',
'content-transfer-encoding': 'binary'
}];
}
);