Skip to content

Commit

Permalink
replace all invalid characters in attribute names when creating varia…
Browse files Browse the repository at this point in the history
…bles (fixes #470)
  • Loading branch information
Rich-Harris committed Apr 12, 2017
1 parent c54bebb commit a47a679
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/generators/dom/visitors/Element/Attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function visitAttribute ( generator, block, state, node, attribut
);
}

const last = `last_${state.parentNode}_${name.replace( /-/g, '_')}`;
const last = `last_${state.parentNode}_${name.replace( /[^a-zA-Z_$]/g, '_')}`;
block.builders.create.addLine( `var ${last} = ${value};` );

const isSelectValueAttribute = name === 'value' && state.parentNodeName === 'select';
Expand Down
14 changes: 14 additions & 0 deletions test/runtime/samples/attribute-namespaced/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
data: { foo: 'bar' },

html: `
<svg>
<use xlink:href="#bar"/>
</svg>
`,

test ( assert, component, target ) {
const use = target.querySelector( 'use' );
assert.equal( use.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ), '#bar' );
}
};
3 changes: 3 additions & 0 deletions test/runtime/samples/attribute-namespaced/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svg>
<use xlink:href="#{{foo}}"/>
</svg>

0 comments on commit a47a679

Please sign in to comment.