File tree 6 files changed +48
-2
lines changed
test/server-side-rendering/samples
attribute-escaped-quotes-spread
6 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -310,7 +310,7 @@ export default class Compiler {
310
310
: `_svelteTransitionManager` ;
311
311
312
312
inlineHelpers += `\n\nvar ${ this . alias ( name ) } = window.${ global } || (window.${ global } = ${ code } );\n\n` ;
313
- } else if ( name === 'escaped' || name === 'missingComponent' ) {
313
+ } else if ( name === 'escaped' || name === 'missingComponent' || name === 'invalidAttributeNameCharacter' ) {
314
314
// vars are an awkward special case... would be nice to avoid this
315
315
const alias = this . alias ( name ) ;
316
316
inlineHelpers += `\n\nconst ${ alias } = ${ code } ;`
Original file line number Diff line number Diff line change
1
+ // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
2
+ // https://infra.spec.whatwg.org/#noncharacter
3
+ export const invalidAttributeNameCharacter = / [ \s ' " < \/ = \u{FDD0} - \u{FDEF} \u{FFFE} \u{FFFF} \u{1FFFE} \u{1FFFF} \u{2FFFE} \u{2FFFF} \u{3FFFE} \u{3FFFF} \u{4FFFE} \u{4FFFF} \u{5FFFE} \u{5FFFF} \u{6FFFE} \u{6FFFF} \u{7FFFE} \u{7FFFF} \u{8FFFE} \u{8FFFF} \u{9FFFE} \u{9FFFF} \u{AFFFE} \u{AFFFF} \u{BFFFE} \u{BFFFF} \u{CFFFE} \u{CFFFF} \u{DFFFE} \u{DFFFF} \u{EFFFE} \u{EFFFF} \u{FFFFE} \u{FFFFF} \u{10FFFE} \u{10FFFF} ] / u;
4
+
1
5
export function spread ( args ) {
2
6
const attributes = Object . assign ( { } , ...args ) ;
3
7
let str = '' ;
4
8
5
9
Object . keys ( attributes ) . forEach ( name => {
10
+ if ( invalidAttributeNameCharacter . test ( name ) ) return ;
11
+
6
12
const value = attributes [ name ] ;
7
13
if ( value === undefined ) return ;
8
14
if ( value === true ) str += " " + name ;
9
- str += " " + name + "=" + JSON . stringify ( value ) ;
15
+
16
+ const escaped = String ( value )
17
+ . replace ( / " / g, '"' )
18
+ . replace ( / ' / g, ''' ) ;
19
+
20
+ str += " " + name + "=" + JSON . stringify ( escaped ) ;
10
21
} ) ;
11
22
12
23
return str ;
Original file line number Diff line number Diff line change
1
+ < div
2
+ foo =""></div><script>alert(42)</script> "
3
+ bar ="'></div><script>alert(42)</script> "
4
+ > </ div >
Original file line number Diff line number Diff line change
1
+ < div {...props} > </ div >
2
+
3
+ < script >
4
+
5
+ export default {
6
+ data ( ) {
7
+ return {
8
+ props : {
9
+ foo : '"></div><script>alert(42)</' + 'script>' ,
10
+ bar : "'></div><script>alert(42)</" + 'script>' ,
11
+ [ '"></div><script>alert(42)</' + 'script>' ] : 'baz'
12
+ }
13
+ } ;
14
+ }
15
+ } ;
16
+ </ script >
Original file line number Diff line number Diff line change
1
+ < div
2
+ foo =""></div><script>alert(42)</script> "
3
+ > </ div >
Original file line number Diff line number Diff line change
1
+ < div foo ={foo} > </ div >
2
+
3
+ < script >
4
+
5
+ export default {
6
+ data ( ) {
7
+ return {
8
+ foo : '"></div><script>alert(42)</' + 'script>'
9
+ } ;
10
+ }
11
+ } ;
12
+ </ script >
You can’t perform that action at this time.
0 commit comments