fix: query path encode query bug

This commit is contained in:
suxiaoxin 2017-11-10 18:07:13 +08:00
parent 02191051f8
commit 2f8087f139
2 changed files with 34 additions and 16 deletions

View File

@ -197,23 +197,27 @@ export default class Run extends Component {
return;
}
const { headers, bodyForm, pathParam, bodyOther, caseEnv, domains, method, pathname, query, bodyType } = this.state;
const urlObj = URL.parse(_.find(domains, item => item.name === caseEnv).domain);
let path = pathname;
pathParam.forEach(item => {
path = path.replace(`:${item.name}`, handleMockWord(item.value) || `:${item.name}`);
});
if (urlObj.pathname) {
if (urlObj.pathname[urlObj.pathname.length - 1] !== '/') {
urlObj.pathname += '/'
const urlObj = URL.parse(URL.resolve(_.find(domains, item => item.name === caseEnv).domain, '.' + path));
let pathQuery = {};
urlObj.query && urlObj.query.split('&').forEach(item=>{
if(item){
item = item.split('=');
pathQuery[item[0]] = item[1];
}
}
})
const href = URL.format({
protocol: urlObj.protocol || 'http',
host: urlObj.host,
pathname: urlObj.pathname ? URL.resolve(urlObj.pathname, '.' + path) : path,
query: this.getQueryObj(query)
pathname: urlObj.pathname,
query: Object.assign(pathQuery, this.getQueryObj(query))
});
let reqBody;
if(bodyType === 'form'){
@ -575,7 +579,16 @@ export default class Run extends Component {
let val = handleMockWord(item.value);
path = path.replace(`:${item.name}`, val || `:${item.name}`);
});
const search = decodeURIComponent(URL.format({ query: this.getQueryObj(query) }));
const pathObj = URL.parse(path);
path = pathObj.pathname;
let pathQuery = {};
pathObj.query && pathObj.query.split('&').forEach(item=>{
if(item){
item = item.split('=');
pathQuery[item[0]] = item[1];
}
})
const search = decodeURIComponent(URL.format({ query: Object.assign(pathQuery, this.getQueryObj(query)) }));
let validResView;
validResView = validRes.map((item, index) => {

View File

@ -193,6 +193,7 @@ class InterfaceColContent extends Component {
}
handleTest = async (interfaceData) => {
console.log(1)
const { currProject } = this.props;
let requestParams = {};
let { case_env } = interfaceData;
@ -207,22 +208,26 @@ class InterfaceColContent extends Component {
case_env = this.state.currColEnv ? this.state.currColEnv : case_env;
let pathQuery = {};
let currDomain = _.find(domains, item => item.name === case_env);
if (!currDomain) {
currDomain = domains[0];
}
const urlObj = URL.parse(currDomain.domain);
if (urlObj.pathname) {
if (urlObj.pathname[urlObj.pathname.length - 1] !== '/') {
urlObj.pathname += '/'
const urlObj = URL.parse(URL.resolve(currDomain.domain, '.' + path));
urlObj.query && urlObj.query.split('&').forEach(item=>{
if(item){
item = item.split('=');
pathQuery[item[0]] = item[1];
}
}
})
const href = URL.format({
protocol: urlObj.protocol || 'http',
host: urlObj.host,
pathname: urlObj.pathname ? URL.resolve(urlObj.pathname, '.' + path) : path,
query: this.getQueryObj(interfaceData.req_query, requestParams)
pathname: urlObj.pathname,
query: Object.assign(pathQuery, this.getQueryObj(interfaceData.req_query, requestParams))
});
let result = { code: 400, msg: '数据异常', validRes: [] };