Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 36d37c0

Browse files
caitpvojtajina
authored andcommitted
fix(jqLite): trim HTML string in jqLite constructor
jQuery will construct DOM nodes containing leading whitespace. Prior to this change, jqLite would throw a nosel minErr due to the first character of the string not being '<'. This change corrects this behaviour by trimming the element string in jqLite constructor before testing for '<'. Closes #6053
1 parent 24699ee commit 36d37c0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/jqLite.js

+3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ function JQLite(element) {
175175
if (element instanceof JQLite) {
176176
return element;
177177
}
178+
if (isString(element)) {
179+
element = trim(element);
180+
}
178181
if (!(this instanceof JQLite)) {
179182
if (isString(element) && element.charAt(0) != '<') {
180183
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');

test/jqLiteSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ describe('jqLite', function() {
6565
});
6666

6767

68+
it('should allow construction of html with leading whitespace', function() {
69+
var nodes = jqLite(' \n\r \r\n<div>1</div><span>2</span>');
70+
expect(nodes[0].parentNode).toBeDefined();
71+
expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment **/;
72+
expect(nodes[0].parentNode).toBe(nodes[1].parentNode);
73+
expect(nodes.length).toBe(2);
74+
expect(nodes[0].innerHTML).toBe('1');
75+
expect(nodes[1].innerHTML).toBe('2');
76+
});
77+
78+
6879
it('should allow creation of comment tags', function() {
6980
var nodes = jqLite('<!-- foo -->');
7081
expect(nodes.length).toBe(1);

0 commit comments

Comments
 (0)