3***@qq.com
3***@qq.com
  • 发布:2021-01-18 12:37
  • 更新:2021-01-21 11:50
  • 阅读:1097

【报Bug】uniapp在 安卓版App atob 解析出的值 不正确

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win7

HBuilderX类型: 正式

HBuilderX版本号: 3.0.4

手机系统: Android

手机系统版本号: Android 10

手机厂商: 华为

手机机型: mate20pro

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

function base64ToUint8Array(base64String) {
const BASE64_MARKER = ';base64,';
     const base64Index = base64String.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
const base64 = base64String.substring(base64Index);
let rawData = Base64.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
console.log('outputArray',outputArray.length)
return outputArray.buffer;
}
let aa = 'data:application/dat;base64,EooBCkQIARJACAgQNBoCrwEgACgAMAA4lNwHQiQIAxIgyCazJ1eoSewjpJyWH675MT5aICOnZ8A1y04eULg5XHRIAFIECAESABAAGkCJEmStGfFunnIh94pH/peMTIbrLoluZpVCCw0JQLe+tSOsDYxLJ1u1OnLF/4ZosFDt+H6TKNTOfj3gu0cSAA2a';
let arrayBuffer = base64ToUint8Array(aa);
let arr = Array.prototype.slice.call(new Uint8Array(arrayBuffer ));
console.log('arrarrarrarr',arr.toString() )
在安卓中的到的是 数组[18,253,1,10,68,8,1,18,64,8,8,16,52,26,2,253,1,32,0,40,0,48,0,56,253,253,7,66,36,8,3,18,32,253,38,253,39,87,253,73,253,35,253,253,253,31,253,253,49,62,90,32,35,253,103,253,53,253,78,30,80,253,57,92,116,72,0,82,4,8,1,18,0,16,0,26,64,253,18,100,253,25,253,110,253,114,33,253,253,71,253,253,253,76,253,253,46,253,110,102,253,66,11,13,9,64,253,253,253,35,253,13,253,75,39,91,253,58,114,253,253,253,104,253,80,253,253,126,253,40,253,253,126,61,253,71,18,0,13,253]

在ios中的到的 [ 18,138,1,10,68,8,1,18,64,8,8,16,52,26,2,175,1,32,0,40,0,48,0,56,148,220,7,66,36,8,3,18,32,200,38,179,39,87,168,73,236,35,164,156,150,31,174,249,49,62,90,32,35,167,103,192,53,203,78,30,80,184,57,92,116,72,0,82,4,8,1,18,0,16,0,26,64,137,18,100,173,25,241,110,158,114,33,247,138,71,254,151,140,76,134,235,46,137,110,102,149,66,11,13,9,64,183,190,181,35,172,13,140,75,39,91,181,58,114,197,255,134,104,176,80,237,248,126,147,40,212,206,126,61,224,187,71,18,0,13,154]

经测试 ios中的值为正确的值

在浏览器中也是ios的值

操作步骤:

直接运行上述方法

预期结果:

安卓得正确的值

实际结果:

安卓得不正确的值

bug描述:

base64 值:data:application/dat;base64,EooBCkQIARJACAgQNBoCrwEgACgAMAA4lNwHQiQIAxIgyCazJ1eoSewjpJyWH675MT5aICOnZ8A1y04eULg5XHRIAFIECAESABAAGkCJEmStGfFunnIh94pH/peMTIbrLoluZpVCCw0JQLe+tSOsDYxLJ1u1OnLF/4ZosFDt+H6TKNTOfj3gu0cSAA2a

在ios中解析出和安卓不同

2021-01-18 12:37 负责人:DCloud_Android_DQQ 分享
已邀请:
DCloud_Android_DQQ

DCloud_Android_DQQ

好,我试试

DCloud_Android_DQQ

DCloud_Android_DQQ

这里的Base64 哪里来的。

DCloud_Android_DQQ

DCloud_Android_DQQ

我这里测试没有复现问题

Android: 荣耀30

IOS: iPhone 7P

对比:

测试代码:

base64ToUint8Array(base64String) {  
				  
				const BASE64_MARKER = ';base64,';  
				const base64Index = base64String.indexOf(BASE64_MARKER) + BASE64_MARKER.length;  
				const base64 = base64String.substring(base64Index);  
				let rawData = atob(base64);  
				const outputArray = new Uint8Array(rawData.length);  
				for (let i = 0; i < rawData.length; ++i) {  
					outputArray[i] = rawData.charCodeAt(i);  
				}  
				console.log('outputArray', outputArray.length)  
				return outputArray.buffer;  
			},  
  
			atobTest:function(){  
				  
				let arrayBuffer = this.base64ToUint8Array(this.aa);  
				let arr = Array.prototype.slice.call(new Uint8Array(arrayBuffer));  
				console.log('arrarrarrarr', arr.toString());  
			},  

  • 3***@qq.com (作者)

    我试了下 还是不对 现在不用这个了 换了种方式 用了个模块 暂时可以用了


    2021-01-21 11:51

3***@qq.com

3***@qq.com (作者)

我这又试了下 还是不对 手机是华为nova 6 se

该问题目前已经被锁定, 无法添加新回复