From 363e544563c553ee5be3b181fb4d738ac8a5b47a Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 6 Dec 2019 10:39:06 +0800 Subject: [PATCH] =?UTF-8?q?BI-56945=20hidden=20danger:=20=E5=95=8Aa?= =?UTF-8?q?=E6=A0=87=E7=BA=A2=E5=80=BC=E6=A0=87=E7=BA=A2=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=20&&=20=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/web/jquery/__test__/fn.test.js | 64 +++++++++++++++++++ src/core/platform/web/jquery/fn.js | 3 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/core/platform/web/jquery/__test__/fn.test.js diff --git a/src/core/platform/web/jquery/__test__/fn.test.js b/src/core/platform/web/jquery/__test__/fn.test.js new file mode 100644 index 000000000..6c23271fd --- /dev/null +++ b/src/core/platform/web/jquery/__test__/fn.test.js @@ -0,0 +1,64 @@ +/** + * @author windy + * @version 2.0 + * Created by windy on 2019/12/6 + */ + +describe("标红test", function () { + + /** + * test_author_windy + */ + it("无多音字标红", function () { + var a = BI.Test.createWidget({ + type: "bi.layout", + }); + a.element.__textKeywordMarked__("无多音字", "w"); + expect(a.element.html()).to.equal("多音字"); + a.destroy(); + }); + + /** + * test_author_windy + */ + it("含有多音字标红", function () { + var a = BI.Test.createWidget({ + type: "bi.layout", + }); + a.element.__textKeywordMarked__("长期协议", "z"); + expect(a.element.html()).to.equal("期协议"); + a.element.__textKeywordMarked__("长期协议", "c"); + expect(a.element.html()).to.equal("期协议"); + a.destroy(); + }); + + /** + * test_author_windy + */ + it("多音字错位标红", function () { + var a = BI.Test.createWidget({ + type: "bi.layout", + }); + a.element.__textKeywordMarked__("呵呵呵", "h"); + expect(a.element.html()).to.equal(""); + a.element.__textKeywordMarked__("呵呵呵", "hh"); + expect(a.element.html()).to.equal("呵呵呵"); + a.element.__textKeywordMarked__("呵呵呵", "hhh"); + expect(a.element.html()).to.equal("呵呵呵"); + a.destroy(); + }); + + /** + * test_author_windy + */ + it("原文和拼音都匹配标红", function () { + var a = BI.Test.createWidget({ + type: "bi.layout", + }); + a.element.__textKeywordMarked__("啊a", "a"); + expect(a.element.html()).to.equal("a"); + a.element.__textKeywordMarked__("a啊", "a"); + expect(a.element.html()).to.equal("a"); + a.destroy(); + }); +}); \ No newline at end of file diff --git a/src/core/platform/web/jquery/fn.js b/src/core/platform/web/jquery/fn.js index 9d94719c6..4798e90af 100644 --- a/src/core/platform/web/jquery/fn.js +++ b/src/core/platform/web/jquery/fn.js @@ -98,7 +98,8 @@ if (BI.jQuery) { } } - if (tidx >= 0) { + // BI-56945 场景: 对'啊a'标红, a为keyword, 此时tidx为1, pidx为0, 此时使用tidx显然'啊'就无法标红了 + if (tidx >= 0 && pidx > tidx) { // 标红的text未encode this.append(BI.htmlEncode(textLeft.substr(0, tidx))); this.append(BI.$("").addClass("bi-keyword-red-mark")