From 30529a9586da5caeb2918381ff92f149ca343acd Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Mon, 27 Nov 2017 13:56:10 +0800 Subject: [PATCH] fix: pipe expression bug --- client/common.js | 21 ++++++++++----- .../InterfaceCol/InterfaceColContent.js | 2 +- package.json | 27 ++++++++++++++++++- test/client/common.test.js | 23 ++++++++++++++++ test/server/mockServer.test.js | 2 +- webpack.alias.js | 10 +++++++ 6 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 test/client/common.test.js create mode 100644 webpack.alias.js diff --git a/client/common.js b/client/common.js index 1b1dde1b..1d7891a4 100755 --- a/client/common.js +++ b/client/common.js @@ -22,7 +22,7 @@ const roleAction = { 'viewGroup': 'guest' } -exports.isJson = function(json){ +function isJson(json){ if(!json) return false; try{ json = json5.parse(json); @@ -32,6 +32,8 @@ exports.isJson = function(json){ } } +exports.isJson = isJson; + exports.checkAuth = (action, role)=>{ return Roles[roleAction[action]] <= Roles[role]; } @@ -237,21 +239,28 @@ function handleValueWithFilter(context){ } } -function handleParamsValue (val, context){ +function handleParamsValue (val, context={}){ const variableRegexp = /\{\s*((?:\$|\@)?.+?)\}/g; if (!val || typeof val !== 'string') { return val; } val = val.trim(); - if (val[0] !== '{' && val.indexOf('{') === -1) { - val = '{' + val + '}'; + if (!/^\{[\s\S]+\}$/.test(val)) { + try{ + return filter(val, handleValueWithFilter(context)) + }catch(err){ + return val; + } } - return val.replace(variableRegexp, function(str, match){ + if(isJson(val)){ + return val; + } + return val.replace(variableRegexp, function(str, match){ match = match.trim(); try{ return filter(match, handleValueWithFilter(context)) }catch(err){ - return match; + return str; } }) } diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js b/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js index e27bd63d..77be96a6 100755 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js @@ -196,7 +196,7 @@ class InterfaceColContent extends Component { const { currProject } = this.props; let requestParams = {}; let { case_env } = interfaceData; - let path = joinPath(currProject.basepath, interfaceData.path); + let path = interfaceData.path; interfaceData.req_params = interfaceData.req_params || []; interfaceData.req_params.forEach(item => { let val = this.handleValue(item.value); diff --git a/package.json b/package.json index 9176c51c..661add95 100755 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-object-rest-spread": "^6.8.0", "babel-plugin-transform-runtime": "^6.9.0", + "babel-plugin-webpack-alias": "^2.1.2", "babel-preset-es2015": "^6.9.0", "babel-preset-react": "^6.5.0", "babel-preset-stage-3": "^6.24.1", @@ -143,9 +144,33 @@ "node": ">= 7.6.0", "npm": ">= 4.1.2" }, + "babel": { + "presets": [ + [ + "es2015", + { + "loose": true, + "modules": "commonjs" + } + ], + "es2017", + "stage-0", + "react" + ], + "plugins": [ + "transform-runtime", + ["webpack-alias", { + "config": "webpack.alias.js" + }] + ] + }, "ava": { "files": [ "test/**/*.js" - ] + ], + "require": [ + "babel-register" + ], + "babel": "inherit" } } diff --git a/test/client/common.test.js b/test/client/common.test.js new file mode 100644 index 00000000..1a3d8062 --- /dev/null +++ b/test/client/common.test.js @@ -0,0 +1,23 @@ +import test from 'ava'; +import { + handleParamsValue +} from '../../client/common.js'; + + +test('handleParamsValue', t => { + const json = JSON.stringify({ + t: 1, + obj: { + name: "dd", + value: "vvvv" + } + }) + + + t.is(handleParamsValue(" aaaa | length"), 4); + t.is(handleParamsValue("aaaa |upper "), 'AAAA') + t.is(handleParamsValue(json), json) + t.is(handleParamsValue(' { dkkdjf }'), 'dkkdjf') + t.is(handleParamsValue(' { dkkdjf | upper | kkk }'), '{ dkkdjf | upper | kkk }') +}); + diff --git a/test/server/mockServer.test.js b/test/server/mockServer.test.js index f01c1621..a6f64bcd 100644 --- a/test/server/mockServer.test.js +++ b/test/server/mockServer.test.js @@ -2,7 +2,7 @@ import test from 'ava'; const rewire = require("rewire"); const mockServer = rewire('../../server/middleware/mockServer.js'); const matchApi = mockServer.__get__('matchApi'); -const mockExtra = require('../../common/mock-extra.js'); + test('matchApi', t => { const apiRule = '/user/:username'; diff --git a/webpack.alias.js b/webpack.alias.js new file mode 100644 index 00000000..a258f21c --- /dev/null +++ b/webpack.alias.js @@ -0,0 +1,10 @@ +const path = require('path') + +module.exports = { + resolve: { + alias: { + 'common': path.resolve(__dirname, 'common'), + 'client': path.resolve(__dirname, 'client') + } + } +} \ No newline at end of file