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..9a03d9142b7 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([]); + }); }); }); });