From 9f865e645428991dcce9d92c932a86706bb1df10 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sat, 22 Jan 2022 20:12:58 -0600 Subject: [PATCH] fix: throw error for invalid tag name --- src/lib/web-worker/worker-constants.ts | 2 ++ src/lib/web-worker/worker-document.ts | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/web-worker/worker-constants.ts b/src/lib/web-worker/worker-constants.ts index 2f49babe..271516ca 100644 --- a/src/lib/web-worker/worker-constants.ts +++ b/src/lib/web-worker/worker-constants.ts @@ -73,3 +73,5 @@ export const windowGetterDimensionMethodNames = ['getComputedStyle']; export const eventTargetMethods = /*#__PURE__*/ commaSplit( 'addEventListener,dispatchEvent,removeEventListener' ); + +export const IS_TAG_REG = /^[A-Z]([A-Z0-9-]*[A-Z0-9])?$/; diff --git a/src/lib/web-worker/worker-document.ts b/src/lib/web-worker/worker-document.ts index 4073062f..5aac93ec 100644 --- a/src/lib/web-worker/worker-document.ts +++ b/src/lib/web-worker/worker-document.ts @@ -5,9 +5,9 @@ import { getInstanceStateValue } from './worker-state'; import { getOrCreateNodeInstance } from './worker-constructors'; import { getPartytownScript } from './worker-exec'; import { isScriptJsType } from './worker-script'; +import { IS_TAG_REG, WinIdKey } from './worker-constants'; import type { Node } from './worker-node'; import { noop, randomId, SCRIPT_TYPE } from '../utils'; -import { WinIdKey } from './worker-constants'; export const DocumentDescriptorMap: PropertyDescriptorMap & ThisType = { body: { @@ -19,6 +19,9 @@ export const DocumentDescriptorMap: PropertyDescriptorMap & ThisType = { createElement: { value(tagName: string) { tagName = tagName.toUpperCase(); + if (!IS_TAG_REG.test(tagName)) { + throw tagName + ' not valid'; + } const winId = this[WinIdKey]; const instanceId = randomId();