From 36d37c0e3880c774d20c014ade60d2331beefa15 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 4 Feb 2014 11:37:09 -0500 Subject: 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 --- src/jqLite.js | 3 +++ test/jqLiteSpec.js | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/jqLite.js b/src/jqLite.js index e5980514..f48dd3c0 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -175,6 +175,9 @@ function JQLite(element) { if (element instanceof JQLite) { return element; } + if (isString(element)) { + element = trim(element); + } if (!(this instanceof JQLite)) { 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'); diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 931f9b2e..a98e94b9 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -65,6 +65,17 @@ describe('jqLite', function() { }); + it('should allow construction of html with leading whitespace', function() { + var nodes = jqLite(' \n\r \r\n