node-webot / wechat

微信公共平台消息接口服务中间件
Other
5.11k stars 1.18k forks source link

xml2js解析出来的对象转换成直接可访问的对象 #250

Closed feifeiiiiiiiiiii closed 8 years ago

feifeiiiiiiiiiii commented 8 years ago

xml2js解析出来的对象转换成直接可访问的对象应该加上如果不是对象的情况,虽然微信的xml数据没有这种情况,个人觉得还是应该处理下比较好

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.01%) to 96.049% when pulling 00a3322a417fa70e3cb6bf104d7b7123de2ec277 on feifeiiiiiiiiiii:master into 471ca31082223de5ccf864578a00c781bfad02a6 on node-webot:master.

JacksonTian commented 8 years ago

给个单元测试来说明这种情况?

feifeiiiiiiiiiii commented 8 years ago

ok

feifeiiiiiiiiiii commented 8 years ago

formatMessage这个函数对外不可可见,所以这里我只能提供一下一组样例

<xml>
   <arraytest>
       <item><![CDATA[item1]]></item>
       <item><![CDATA[item2]]></item>
   </arraytest>
</xml>

当然微信目前是没有这种类似数据的

按照没修改之前得到的结果是

{ arraytest: { item: [ {}, {} ] } }

其实正常结果应该是

{ arraytest: { item: [ 'item1', 'item2' ] } }

我说的对吧?

JacksonTian commented 8 years ago

用rewire可以导出私有方法。

feifeiiiiiiiiiii commented 8 years ago

ok 等我用rewire加上测试用例

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.9%) to 96.96% when pulling 890c36cde71a9754ee0f507fe863413514e2d5d3 on feifeiiiiiiiiiii:master into 471ca31082223de5ccf864578a00c781bfad02a6 on node-webot:master.