From 5498ab65f56df7f8f6ad3a5971e492ad6341ec94 Mon Sep 17 00:00:00 2001 From: Chema Date: Wed, 2 Jan 2013 19:55:18 +0100 Subject: [PATCH 1/2] Text and fix for 2464 --- src/language/HTMLUtils.js | 5 +++++ test/spec/CodeHintUtils-test.js | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/language/HTMLUtils.js b/src/language/HTMLUtils.js index 86af2454d6b..4be550d661b 100644 --- a/src/language/HTMLUtils.js +++ b/src/language/HTMLUtils.js @@ -133,6 +133,11 @@ define(function (require, exports, module) { while (TokenUtils.moveNextToken(forwardCtx) && forwardCtx.token.className !== "tag") { if (forwardCtx.token.className === "attribute") { + // If the current tag is not closed, codemirror may return the next opening + // tag as an attribute. Stop the search loop in that case. + if (forwardCtx.token.string.indexOf("<") === 0) { + break; + } attrs.push(forwardCtx.token.string); } else if (forwardCtx.token.className === "error") { // If we type the first letter of the next attribute, it comes as an error diff --git a/test/spec/CodeHintUtils-test.js b/test/spec/CodeHintUtils-test.js index 8bd154728f7..3e722cc95bc 100644 --- a/test/spec/CodeHintUtils-test.js +++ b/test/spec/CodeHintUtils-test.js @@ -332,6 +332,16 @@ define(function (require, exports, module) { var attrs = HTMLUtils.getTagAttributes(myEditor, pos); expect(attrs.sort()).toEqual(["id", "class", "lang", "align", "title"].sort()); }); + + it("should not find attributes of other tags on an opened tag", function () { + var pos = {"ch": 0, "line": 0}; + setContentAndUpdatePos(pos, + ["", ""], + "
", "", ""]); + var attrs = HTMLUtils.getTagAttributes(myEditor, pos); + expect(attrs).toEqual([]); + }); }); }); }); From d2e320e391694e5375fb47bfa2fa4b175fc14c51 Mon Sep 17 00:00:00 2001 From: Chema Date: Fri, 4 Jan 2013 11:49:12 +0100 Subject: [PATCH 2/2] Fix test for #2464 so it produces valid html --- test/spec/CodeHintUtils-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/CodeHintUtils-test.js b/test/spec/CodeHintUtils-test.js index 3e722cc95bc..9a03d9142b7 100644 --- a/test/spec/CodeHintUtils-test.js +++ b/test/spec/CodeHintUtils-test.js @@ -338,7 +338,7 @@ define(function (require, exports, module) { setContentAndUpdatePos(pos, ["", ""], "
", "", ""]); + ["
", "
", "", ""]); var attrs = HTMLUtils.getTagAttributes(myEditor, pos); expect(attrs).toEqual([]); });