mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-15 05:10:47 +08:00
fix: pipe expression bug
This commit is contained in:
parent
517e9b30fb
commit
30529a9586
@ -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;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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);
|
||||
|
27
package.json
27
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"
|
||||
}
|
||||
}
|
||||
|
23
test/client/common.test.js
Normal file
23
test/client/common.test.js
Normal file
@ -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 }')
|
||||
});
|
||||
|
@ -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';
|
||||
|
10
webpack.alias.js
Normal file
10
webpack.alias.js
Normal file
@ -0,0 +1,10 @@
|
||||
const path = require('path')
|
||||
|
||||
module.exports = {
|
||||
resolve: {
|
||||
alias: {
|
||||
'common': path.resolve(__dirname, 'common'),
|
||||
'client': path.resolve(__dirname, 'client')
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user