File tree Expand file tree Collapse file tree 4 files changed +105
-4
lines changed
src/compiler/phases/1-parse/state
tests/parser-legacy/samples/attribute-unquoted Expand file tree Collapse file tree 4 files changed +105
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: allow unquoted slash in attributes
Original file line number Diff line number Diff line change @@ -504,8 +504,24 @@ function read_attribute(parser) {
504
504
let value = true ;
505
505
if ( parser . eat ( '=' ) ) {
506
506
parser . allow_whitespace ( ) ;
507
- value = read_attribute_value ( parser ) ;
508
- end = parser . index ;
507
+
508
+ if ( parser . template [ parser . index ] === '/' && parser . template [ parser . index + 1 ] === '>' ) {
509
+ const char_start = parser . index ;
510
+ parser . index ++ ; // consume '/'
511
+ value = [
512
+ {
513
+ start : char_start ,
514
+ end : char_start + 1 ,
515
+ type : 'Text' ,
516
+ raw : '/' ,
517
+ data : '/'
518
+ }
519
+ ] ;
520
+ end = parser . index ;
521
+ } else {
522
+ value = read_attribute_value ( parser ) ;
523
+ end = parser . index ;
524
+ }
509
525
} else if ( parser . match_regex ( regex_starts_with_quote_characters ) ) {
510
526
e . expected_token ( parser . index , '=' ) ;
511
527
}
Original file line number Diff line number Diff line change 1
- <div class =foo ></div >
1
+ <div class =foo ></div >
2
+ <a href =/>home</a >
3
+ <a href =/foo >home</a >
Original file line number Diff line number Diff line change 2
2
"html" : {
3
3
"type" : " Fragment" ,
4
4
"start" : 0 ,
5
- "end" : 21 ,
5
+ "end" : 62 ,
6
6
"children" : [
7
7
{
8
8
"type" : " Element" ,
27
27
}
28
28
],
29
29
"children" : []
30
+ },
31
+ {
32
+ "type" : " Text" ,
33
+ "start" : 21 ,
34
+ "end" : 22 ,
35
+ "raw" : " \n " ,
36
+ "data" : " \n "
37
+ },
38
+ {
39
+ "type" : " Element" ,
40
+ "start" : 22 ,
41
+ "end" : 40 ,
42
+ "name" : " a" ,
43
+ "attributes" : [
44
+ {
45
+ "type" : " Attribute" ,
46
+ "start" : 25 ,
47
+ "end" : 31 ,
48
+ "name" : " href" ,
49
+ "value" : [
50
+ {
51
+ "start" : 30 ,
52
+ "end" : 31 ,
53
+ "type" : " Text" ,
54
+ "raw" : " /" ,
55
+ "data" : " /"
56
+ }
57
+ ]
58
+ }
59
+ ],
60
+ "children" : [
61
+ {
62
+ "type" : " Text" ,
63
+ "start" : 32 ,
64
+ "end" : 36 ,
65
+ "raw" : " home" ,
66
+ "data" : " home"
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "type" : " Text" ,
72
+ "start" : 40 ,
73
+ "end" : 41 ,
74
+ "raw" : " \n " ,
75
+ "data" : " \n "
76
+ },
77
+ {
78
+ "type" : " Element" ,
79
+ "start" : 41 ,
80
+ "end" : 62 ,
81
+ "name" : " a" ,
82
+ "attributes" : [
83
+ {
84
+ "type" : " Attribute" ,
85
+ "start" : 44 ,
86
+ "end" : 53 ,
87
+ "name" : " href" ,
88
+ "value" : [
89
+ {
90
+ "start" : 49 ,
91
+ "end" : 53 ,
92
+ "type" : " Text" ,
93
+ "raw" : " /foo" ,
94
+ "data" : " /foo"
95
+ }
96
+ ]
97
+ }
98
+ ],
99
+ "children" : [
100
+ {
101
+ "type" : " Text" ,
102
+ "start" : 54 ,
103
+ "end" : 58 ,
104
+ "raw" : " home" ,
105
+ "data" : " home"
106
+ }
107
+ ]
30
108
}
31
109
]
32
110
}
You can’t perform that action at this time.
0 commit comments