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
46
46
} )
47
47
48
48
// Special Elements (can contain anything)
49
- const isScriptOrStyle = makeMap ( 'script,style' , true )
49
+ const isPlainTextElement = makeMap ( 'script,style,textarea ' , true )
50
50
const reCache = { }
51
51
52
52
const decodingMap = {
@@ -72,8 +72,8 @@ export function parseHTML (html, options) {
72
72
let last , lastTag
73
73
while ( html ) {
74
74
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 ) ) {
77
77
let textEnd = html . indexOf ( '<' )
78
78
if ( textEnd === 0 ) {
79
79
// Comment:
@@ -153,7 +153,7 @@ export function parseHTML (html, options) {
153
153
var endTagLength = 0
154
154
var rest = html . replace ( reStackedTag , function ( all , text , endTag ) {
155
155
endTagLength = endTag . length
156
- if ( stackedTag !== 'script' && stackedTag !== 'style' && stackedTag !== 'noscript' ) {
156
+ if ( ! isPlainTextElement ( stackedTag ) && stackedTag !== 'noscript' ) {
157
157
text = text
158
158
. replace ( / < ! - - ( [ \s \S ] * ?) - - > / g, '$1' )
159
159
. 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', () => {
506
506
expect ( ast . tag ) . toBe ( 'div' )
507
507
expect ( ast . children . length ) . toBe ( 0 )
508
508
} )
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
+ } )
509
534
} )
You can’t perform that action at this time.
0 commit comments