fix(field): delegate autocomplete to inputElement for security

This commit is contained in:
Joren Broekema 2019-10-25 17:38:21 +02:00 committed by Thomas Allmer
parent 65a94c949a
commit 8a4dd7e07d
2 changed files with 19 additions and 0 deletions

View file

@ -49,6 +49,10 @@ export class LionField extends FormControlMixin(
type: String, type: String,
reflect: true, reflect: true,
}, },
autocomplete: {
type: String,
reflect: true,
},
}; };
} }
@ -141,6 +145,10 @@ export class LionField extends FormControlMixin(
if (changedProps.has('name')) { if (changedProps.has('name')) {
this.inputElement.name = this.name; this.inputElement.name = this.name;
} }
if (changedProps.has('autocomplete')) {
this.inputElement.autocomplete = this.autocomplete;
}
} }
/** /**

View file

@ -124,6 +124,17 @@ describe('<lion-field>', () => {
expect(el.$$slot('input').value).to.equal('one'); expect(el.$$slot('input').value).to.equal('one');
}); });
// This is necessary for security, so that inputElements autocomplete can be set to 'off'
it('delegates autocomplete property', async () => {
const el = await fixture(html`<${tag}>${inputSlot}</${tag}>`);
expect(el.inputElement.autocomplete).to.equal('');
expect(el.inputElement.hasAttribute('autocomplete')).to.be.false;
el.autocomplete = 'off';
await el.updateComplete;
expect(el.inputElement.autocomplete).to.equal('off');
expect(el.inputElement.getAttribute('autocomplete')).to.equal('off');
});
// TODO: find out if we could put all listeners on this.value (instead of this.inputElement.value) // TODO: find out if we could put all listeners on this.value (instead of this.inputElement.value)
// and make it act on this.value again // and make it act on this.value again
it('has a class "state-filled" if this.value is filled', async () => { it('has a class "state-filled" if this.value is filled', async () => {