From 2f8087f1392022b006d7f9128dc727527cfc6c3c Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Fri, 10 Nov 2017 18:07:13 +0800 Subject: [PATCH] fix: query path encode query bug --- client/components/Postman/Postman.js | 31 +++++++++++++------ .../InterfaceCol/InterfaceColContent.js | 19 +++++++----- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/client/components/Postman/Postman.js b/client/components/Postman/Postman.js index e5e5d6b2..96f39109 100755 --- a/client/components/Postman/Postman.js +++ b/client/components/Postman/Postman.js @@ -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) => { diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js b/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js index 019e578e..fcac7b74 100755 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js @@ -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: [] };