mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-19 12:01:07 +00:00
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
This commit is contained in:
parent
24699ee8f0
commit
36d37c0e38
2 changed files with 14 additions and 0 deletions
|
|
@ -175,6 +175,9 @@ function JQLite(element) {
|
||||||
if (element instanceof JQLite) {
|
if (element instanceof JQLite) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
if (isString(element)) {
|
||||||
|
element = trim(element);
|
||||||
|
}
|
||||||
if (!(this instanceof JQLite)) {
|
if (!(this instanceof JQLite)) {
|
||||||
if (isString(element) && element.charAt(0) != '<') {
|
if (isString(element) && element.charAt(0) != '<') {
|
||||||
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
|
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,17 @@ describe('jqLite', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should allow construction of html with leading whitespace', function() {
|
||||||
|
var nodes = jqLite(' \n\r \r\n<div>1</div><span>2</span>');
|
||||||
|
expect(nodes[0].parentNode).toBeDefined();
|
||||||
|
expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment **/;
|
||||||
|
expect(nodes[0].parentNode).toBe(nodes[1].parentNode);
|
||||||
|
expect(nodes.length).toBe(2);
|
||||||
|
expect(nodes[0].innerHTML).toBe('1');
|
||||||
|
expect(nodes[1].innerHTML).toBe('2');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should allow creation of comment tags', function() {
|
it('should allow creation of comment tags', function() {
|
||||||
var nodes = jqLite('<!-- foo -->');
|
var nodes = jqLite('<!-- foo -->');
|
||||||
expect(nodes.length).toBe(1);
|
expect(nodes.length).toBe(1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue