File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
test/unit/modules/compiler Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ let IS_REGEX_CAPTURING_BROKEN = false
4646} )
4747
4848// Special Elements (can contain anything)
49- const isScriptOrStyle = makeMap ( 'script,style' , true )
49+ const isPlainTextElement = makeMap ( 'script,style,textarea ' , true )
5050const reCache = { }
5151
5252const decodingMap = {
@@ -72,8 +72,8 @@ export function parseHTML (html, options) {
7272 let last , lastTag
7373 while ( html ) {
7474 last = html
75- // Make sure we're not in a script or style element
76- if ( ! lastTag || ! isScriptOrStyle ( lastTag ) ) {
75+ // Make sure we're not in a plaintext content element like script/style
76+ if ( ! lastTag || ! isPlainTextElement ( lastTag ) ) {
7777 let textEnd = html . indexOf ( '<' )
7878 if ( textEnd === 0 ) {
7979 // Comment:
@@ -153,7 +153,7 @@ export function parseHTML (html, options) {
153153 var endTagLength = 0
154154 var rest = html . replace ( reStackedTag , function ( all , text , endTag ) {
155155 endTagLength = endTag . length
156- if ( stackedTag !== 'script' && stackedTag !== 'style' && stackedTag !== 'noscript' ) {
156+ if ( ! isPlainTextElement ( stackedTag ) && stackedTag !== 'noscript' ) {
157157 text = text
158158 . replace ( / < ! - - ( [ \s \S ] * ?) - - > / g, '$1' )
159159 . replace ( / < ! \[ C D A T A \[ ( [ \s \S ] * ?) ] ] > / g, '$1' )
Original file line number Diff line number Diff line change @@ -506,4 +506,29 @@ describe('parser', () => {
506506 expect ( ast . tag ) . toBe ( 'div' )
507507 expect ( ast . children . length ) . toBe ( 0 )
508508 } )
509+
510+ it ( 'parse content in textarea as text' , ( ) => {
511+ const options = extend ( { } , baseOptions )
512+
513+ const whitespace = parse ( `
514+ <textarea>
515+ <p>Test 1</p>
516+ test2
517+ </textarea>
518+ ` , options )
519+ expect ( whitespace . tag ) . toBe ( 'textarea' )
520+ expect ( whitespace . children . length ) . toBe ( 1 )
521+ expect ( whitespace . children [ 0 ] . type ) . toBe ( 3 )
522+ // textarea is whitespace sensitive
523+ expect ( whitespace . children [ 0 ] . text ) . toBe ( `
524+ <p>Test 1</p>
525+ test2
526+ ` )
527+
528+ const comment = parse ( '<textarea><!--comment--></textarea>' , options )
529+ expect ( comment . tag ) . toBe ( 'textarea' )
530+ expect ( comment . children . length ) . toBe ( 1 )
531+ expect ( comment . children [ 0 ] . type ) . toBe ( 3 )
532+ expect ( comment . children [ 0 ] . text ) . toBe ( '<!--comment-->' )
533+ } )
509534} )
You can’t perform that action at this time.
0 commit comments