Lock down element type creation

This commit is contained in:
Timothy Farrell 2017-02-02 20:26:33 -06:00
parent 1935f4b045
commit 40139e1c02
2 changed files with 15 additions and 5 deletions

View File

@ -0,0 +1,5 @@
export const ALLOWED_SETTABLE_PROPERTIES = 'style lang dataset dir tabIndex textContent title scrollTop scrollLeft className width height'.split(
' '
);
export const DISALLOWED_ELEMENTS = 'script embed object style'.split(' ');
export const OVERRIDING_EVENTS = ['contextmenu', 'dragover', 'drop'];

View File

@ -1,11 +1,12 @@
import { isFunction } from 'trimkit';
import { supportsPassive } from './utils.js';
import {
ALLOWED_SETTABLE_PROPERTIES,
DISALLOWED_ELEMENTS,
OVERRIDING_EVENTS
} from './constants.js';
const ALLOWED_SETTABLE_PROPERTIES = 'style lang dataset dir tabIndex title scrollTop scrollLeft className width height'.split(
' '
);
const OVERRIDING_EVENTS = ['contextmenu', 'dragover', 'drop'];
function getEventList(element) {
const evtString = element.getAttribute('evl');
return evtString ? evtString.split(';') : [];
@ -88,8 +89,12 @@ export function Projector(domRoot) {
if (type === 3) {
element = document.createTextNode(props.textContent);
} else if (type === 1) {
if (DISALLOWED_ELEMENTS.includes(name)) {
element = document.createElement('div');
} else {
element = document.createElement(name);
}
}
elementMap.set((element._id = id), element);
setAttributes(element, props);