File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed
test/unit/modules/compiler Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ export function parseHTML (html, options) {
9191 last = html
9292 // Make sure we're not in a script or style element
9393 if ( ! lastTag || ! isSpecialTag ( lastTag , options . sfc , stack ) ) {
94- const textEnd = html . indexOf ( '<' )
94+ let textEnd = html . indexOf ( '<' )
9595 if ( textEnd === 0 ) {
9696 // Comment:
9797 if ( / ^ < ! - - / . test ( html ) ) {
@@ -137,16 +137,24 @@ export function parseHTML (html, options) {
137137 }
138138 }
139139
140- let text
141- if ( textEnd >= 0 ) {
140+ let text , rest
141+ if ( textEnd > 0 ) {
142+ rest = html . slice ( textEnd )
143+ while ( ! startTagOpen . test ( rest ) && ! endTag . test ( rest ) ) {
144+ // < in plain text, be forgiving and treat it as text
145+ textEnd += rest . indexOf ( '<' , 1 )
146+ rest = html . slice ( textEnd )
147+ }
142148 text = html . substring ( 0 , textEnd )
143149 advance ( textEnd )
144- } else {
150+ }
151+
152+ if ( textEnd < 0 ) {
145153 text = html
146154 html = ''
147155 }
148156
149- if ( options . chars ) {
157+ if ( options . chars && text ) {
150158 options . chars ( text )
151159 }
152160 } else {
Original file line number Diff line number Diff line change @@ -375,4 +375,13 @@ describe('parser', () => {
375375 expect ( code . children [ 2 ] . type ) . toBe ( 3 )
376376 expect ( code . children [ 2 ] . text ) . toBe ( '\n ' )
377377 } )
378+
379+ it ( 'forgivingly handle < in plain text' , ( ) => {
380+ const options = extend ( { } , baseOptions )
381+ const ast = parse ( '<p>1 < 2 < 3</p>' , options )
382+ expect ( ast . tag ) . toBe ( 'p' )
383+ expect ( ast . children . length ) . toBe ( 1 )
384+ expect ( ast . children [ 0 ] . type ) . toBe ( 3 )
385+ expect ( ast . children [ 0 ] . text ) . toBe ( '1 < 2 < 3' )
386+ } )
378387} )
You can’t perform that action at this time.
0 commit comments