- 当前 Bug 的表现(可附上截图)
n
使用npm引入了urlencode包以后,运行报错
去掉这行代码,就不会报错,因为要用到urlencode,所以必须引入。说明:npm的编译没有问题。
- 预期表现
应该正常执行
- 复现路径
- 提供一个最简复现 Demo
这个js文件require了urlencode,然后被页面的index.js引用
const md5 = require(’./md5.js’);
const urlencode = require(‘urlencode’);
const sortData = function (data) {
let keys = Object.keys(data).sort();
let result = {}
for (let i = 0; i < keys.length; i++) {
let value = data[keys[i]]
if (value instanceof Object) {
value = sortData(value)
}
result[keys[i]] = value
}
return result;
}
const makeUrl = function (method_tag, params) {
console.log(‘Call makeUrl:’, method_tag, params)
let time = (new Date()).valueOf();
let token = ‘test’;
let tag = method_tag;
let params_str = JSON.stringify(sortData(params))
let sign_data = ‘createTime=’ + time + ‘params=’ + params_str+‘tag=’+tag+‘token=’+token;
let url = 'http://qae.qunar.com/api/router?’;
let createTime = time;
let sign = md5.md5(sign_data).toLowerCase();
console.log(sign_data, sign.toLowerCase())
params_str = urlencode(params_str);
return url + ‘token=’ + token + ‘&tag’ + method_tag + ‘&token’ + token + ‘&createTime’ + time + ‘¶ms’ + params_str;
}
module.exports = {
makeUrl: makeUrl
}