diff options
| author | Shyam Seshadri | 2013-01-19 10:21:17 +0530 |
|---|---|---|
| committer | Misko Hevery | 2013-02-14 14:43:31 -0800 |
| commit | 3d0f11212ffcdac060fa4bb990e217e3a0e229fc (patch) | |
| tree | a5da5c77b00353335929342ebf1619e1853d2b26 | |
| parent | 6194e002e2f8860218076a7a5ecf945b0d981843 (diff) | |
| download | angular.js-3d0f11212ffcdac060fa4bb990e217e3a0e229fc.tar.bz2 | |
fix(compiler): Allow startingTag method to handle text / comment nodes
| -rw-r--r-- | src/Angular.js | 15 | ||||
| -rw-r--r-- | test/AngularSpec.js | 7 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/Angular.js b/src/Angular.js index 27ef157d..5195489e 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -777,9 +777,18 @@ function startingTag(element) { // are not allowed to have children. So we just ignore it. element.html(''); } catch(e) {} - return jqLite('<div>').append(element).html(). - match(/^(<[^>]+>)/)[1]. - replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); }); + // As Per DOM Standards + var TEXT_NODE = 3; + var elemHtml = jqLite('<div>').append(element).html(); + try { + return element[0].nodeType === TEXT_NODE ? lowercase(elemHtml) : + elemHtml. + match(/^(<[^>]+>)/)[1]. + replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); }); + } catch(e) { + return lowercase(elemHtml); + } + } diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 1ead504f..e734decf 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -673,6 +673,13 @@ describe('angular', function() { toBe('<ng-abc x="2A">'); }); }); + + describe('startingTag', function() { + it('should allow passing in Nodes instead of Elements', function() { + var txtNode = document.createTextNode('some text'); + expect(startingTag(txtNode)).toBe('some text'); + }); + }); describe('snake_case', function(){ it('should convert to snake_case', function() { |
