This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +19
-3
lines changed
2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -777,9 +777,18 @@ function startingTag(element) {
777
777
// are not allowed to have children. So we just ignore it.
778
778
element . html ( '' ) ;
779
779
} catch ( e ) { }
780
- return jqLite ( '<div>' ) . append ( element ) . html ( ) .
781
- match ( / ^ ( < [ ^ > ] + > ) / ) [ 1 ] .
782
- replace ( / ^ < ( [ \w \- ] + ) / , function ( match , nodeName ) { return '<' + lowercase ( nodeName ) ; } ) ;
780
+ // As Per DOM Standards
781
+ var TEXT_NODE = 3 ;
782
+ var elemHtml = jqLite ( '<div>' ) . append ( element ) . html ( ) ;
783
+ try {
784
+ return element [ 0 ] . nodeType === TEXT_NODE ? lowercase ( elemHtml ) :
785
+ elemHtml .
786
+ match ( / ^ ( < [ ^ > ] + > ) / ) [ 1 ] .
787
+ replace ( / ^ < ( [ \w \- ] + ) / , function ( match , nodeName ) { return '<' + lowercase ( nodeName ) ; } ) ;
788
+ } catch ( e ) {
789
+ return lowercase ( elemHtml ) ;
790
+ }
791
+
783
792
}
784
793
785
794
Original file line number Diff line number Diff line change @@ -673,6 +673,13 @@ describe('angular', function() {
673
673
toBe ( '<ng-abc x="2A">' ) ;
674
674
} ) ;
675
675
} ) ;
676
+
677
+ describe ( 'startingTag' , function ( ) {
678
+ it ( 'should allow passing in Nodes instead of Elements' , function ( ) {
679
+ var txtNode = document . createTextNode ( 'some text' ) ;
680
+ expect ( startingTag ( txtNode ) ) . toBe ( 'some text' ) ;
681
+ } ) ;
682
+ } ) ;
676
683
677
684
describe ( 'snake_case' , function ( ) {
678
685
it ( 'should convert to snake_case' , function ( ) {
You can’t perform that action at this time.
0 commit comments