File tree 2 files changed +76
-0
lines changed
2 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -1015,6 +1015,71 @@ describe('compiler: parse', () => {
1015
1015
} )
1016
1016
} )
1017
1017
1018
+ // https://github.com/vuejs/vue-next/issues/4251
1019
+ test ( 'class attribute should ignore whitespace when parsed' , ( ) => {
1020
+ const ast = baseParse ( '<div class=" \n\t c \t\n "></div>' )
1021
+ const element = ast . children [ 0 ] as ElementNode
1022
+
1023
+ expect ( element ) . toStrictEqual ( {
1024
+ children : [ ] ,
1025
+ codegenNode : undefined ,
1026
+ isSelfClosing : false ,
1027
+ loc : {
1028
+ end : {
1029
+ column : 10 ,
1030
+ line : 3 ,
1031
+ offset : 29
1032
+ } ,
1033
+ source : '<div class=" \n\t c \t\n "></div>' ,
1034
+ start : {
1035
+ column : 1 ,
1036
+ line : 1 ,
1037
+ offset : 0
1038
+ }
1039
+ } ,
1040
+ ns : 0 ,
1041
+ props : [
1042
+ {
1043
+ loc : {
1044
+ end : {
1045
+ column : 3 ,
1046
+ line : 3 ,
1047
+ offset : 22
1048
+ } ,
1049
+ source : 'class=" \n\t c \t\n "' ,
1050
+ start : {
1051
+ column : 6 ,
1052
+ line : 1 ,
1053
+ offset : 5
1054
+ }
1055
+ } ,
1056
+ name : 'class' ,
1057
+ type : 6 ,
1058
+ value : {
1059
+ content : 'c' ,
1060
+ loc : {
1061
+ end : {
1062
+ column : 3 ,
1063
+ line : 3 ,
1064
+ offset : 22
1065
+ } ,
1066
+ source : '" \n\t c \t\n "' ,
1067
+ start : {
1068
+ column : 12 ,
1069
+ line : 1 ,
1070
+ offset : 11
1071
+ }
1072
+ } ,
1073
+ type : 2
1074
+ }
1075
+ }
1076
+ ] ,
1077
+ tag : 'div' ,
1078
+ tagType : 0 ,
1079
+ type : 1
1080
+ } )
1081
+ } )
1082
+
1018
1083
test ( 'directive with no value' , ( ) => {
1019
1084
const ast = baseParse ( '<div v-if/>' )
1020
1085
const directive = ( ast . children [ 0 ] as ElementNode ) . props [ 0 ]
Original file line number Diff line number Diff line change @@ -716,6 +716,17 @@ function parseAttributes(
716
716
}
717
717
718
718
const attr = parseAttribute ( context , attributeNames )
719
+
720
+ // Trim whitespace between class
721
+ // https://github.com/vuejs/vue-next/issues/4251
722
+ if (
723
+ attr . type === NodeTypes . ATTRIBUTE &&
724
+ attr . value &&
725
+ attr . name === 'class'
726
+ ) {
727
+ attr . value . content = attr . value . content . replace ( / \s + / g, ' ' ) . trim ( )
728
+ }
729
+
719
730
if ( type === TagType . Start ) {
720
731
props . push ( attr )
721
732
}
You can’t perform that action at this time.
0 commit comments