From 3cdf99c5b19f183ad7bdc183920f840a1bbee770 Mon Sep 17 00:00:00 2001 From: Bosn Ma Date: Fri, 4 Apr 2014 10:04:57 +0800 Subject: [PATCH] MockJS tag escaption handler --- README.md | 7 +++++++ UPDATELOG.md | 1 + WebContent/demo/mock.plugin/index.htm | 2 +- .../rigel/rap/mock/service/impl/MockMgrImpl.java | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9594895..1ace316 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,13 @@ id|+1 @mock=100 在备注里,MOCK标签和普通的备注需要用分号隔开,比如一个参数叫userId,备注信息是"用户ID", mock标签是@mock=123,则在备注中应该填写:`用户ID;@mock=123` +#### MockJS模板的转义 + +变量名 备注 结果 +escape @mock="123" "escape" : "\"123\"" +noEscape @{mock}=[1,2,3] "noEscape" : [1,2,3] + +明确不需要转义时,只需要写@{mock}即可 ### for RD 之 Console ### diff --git a/UPDATELOG.md b/UPDATELOG.md index cce75ea..cb39286 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -1,4 +1,5 @@ ### rap v0.8.1 ### +* [BUG] 修复@行列 提出的MockJS模板转义问题。2014-04-04 * [BUG] 修复数据导入错误。 2014-04-02 * [功能] 增加pageTester对[action], {action]的URL语法的支持。 2014-04-02 * [BUG] 修复@行列 提出的KISSY complete的问题。 2014-03-27 diff --git a/WebContent/demo/mock.plugin/index.htm b/WebContent/demo/mock.plugin/index.htm index bf103b1..0cf91a2 100644 --- a/WebContent/demo/mock.plugin/index.htm +++ b/WebContent/demo/mock.plugin/index.htm @@ -28,7 +28,7 @@ url : url, dataType : 'json', type : 'get', - success : function(data) { + complete : function(data) { console.log(data); Node.one('#container').html( JSON.stringify(data, null, 4)); diff --git a/src/com/taobao/rigel/rap/mock/service/impl/MockMgrImpl.java b/src/com/taobao/rigel/rap/mock/service/impl/MockMgrImpl.java index 3e15e17..1e4a35c 100644 --- a/src/com/taobao/rigel/rap/mock/service/impl/MockMgrImpl.java +++ b/src/com/taobao/rigel/rap/mock/service/impl/MockMgrImpl.java @@ -15,6 +15,7 @@ import com.taobao.rigel.rap.common.ArrayUtils; import com.taobao.rigel.rap.common.MockjsRunner; import com.taobao.rigel.rap.common.NumberUtils; +import com.taobao.rigel.rap.common.StringUtils; import com.taobao.rigel.rap.mock.service.MockMgr; import com.taobao.rigel.rap.project.bo.Action; import com.taobao.rigel.rap.project.bo.Parameter; @@ -601,10 +602,15 @@ private String mockValue(Parameter para, int index) { private String mockjsValue(Parameter para, int index) { String[] tags = para.getMockDataTEMP().split(";"); + boolean escape = true; Map tagMap = new HashMap(); parseTags(tags, tagMap, true); String returnValue = "1"; String mockValue = tagMap.get("mock"); + if (mockValue == null || mockValue.isEmpty()) { + mockValue = tagMap.get("{mock}"); + escape = false; + } if (mockValue != null && !mockValue.isEmpty()) { if (mockValue.startsWith("[") && mockValue.endsWith("]")) { return mockValue; @@ -612,6 +618,9 @@ private String mockjsValue(Parameter para, int index) { || para.getDataType().equals("boolean")) { return mockValue; } else { + if (escape) { + mockValue = StringUtils.escapeInJ(mockValue); + } return "\"" + mockValue + "\""; } @@ -694,6 +703,11 @@ private void parseTags(String[] tags, Map tagMap, if (tagArr.length > 1) { tagMap.put("mock", tagArr[1]); } + } else if (tag.startsWith("@{mock}")) { + String[] tagArr = tag.split("="); + if (tagArr.length > 1) { + tagMap.put("{mock}", tagArr[1]); + } } } }