{"record":{"id":"36ba0b7535c05eef","repo":"videojs/video.js","slug":"class-has-illegal-whitespace-characters","errorCode":null,"errorMessage":"class has illegal whitespace characters","messagePattern":"class has illegal whitespace characters","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/js/utils/dom.js","lineNumber":47,"sourceCode":"  // will have a length of 0, failing this check.\n  return typeof str === 'string' && Boolean(str.trim());\n}\n\n/**\n * Throws an error if the passed string has whitespace. This is used by\n * class methods to be relatively consistent with the classList API.\n *\n * @private\n * @param  {string} str\n *         The string to check for whitespace.\n *\n * @throws {Error}\n *         Throws an error if there is whitespace in the string.\n */\nfunction throwIfWhitespace(str) {\n  // str.indexOf instead of regex because str.indexOf is faster performance wise.\n  if (str.indexOf(' ') >= 0) {\n    throw new Error('class has illegal whitespace characters');\n  }\n}\n\n/**\n * Whether the current DOM interface appears to be real (i.e. not simulated).\n *\n * @return {boolean}\n *         Will be `true` if the DOM appears to be real, `false` otherwise.\n */\nexport function isReal() {\n  // Both document and window will never be undefined thanks to `global`.\n  return document === window.document;\n}\n\n/**\n * Determines, via duck typing, whether or not a value is a DOM element.\n *\n * @param  {*} value","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/videojs/video.js/blob/c3a7e0e6d20cf5400c9afbee29965fe4dff393c2/src/js/utils/dom.js#L29-L65","documentation":"Thrown by the private throwIfWhitespace helper (invoked from dom.hasClass) when the class-name argument contains a space. Element.classList.contains treats its argument as a single token, so a multi-class string would silently never match; video.js throws to surface the bug.","triggerScenarios":"Calling dom.hasClass(element, 'foo bar') or any internal path (component class checks, control bar state checks) that passes a compound class string. Also triggered by user-derived class data that was built with join(' ').","commonSituations":"Checking for a compound class ('vjs-playing vjs-has-started') instead of one class at a time; passing template literals like `${base} ${modifier}` into hasClass; data-driven class lists concatenated with spaces.","solutions":["Pass a single class token to hasClass.","Split multi-class strings and check each: classes.split(' ').every(c => hasClass(el, c)).","Prefer addClass/removeClass for multi-class operations (they already split on whitespace)."],"exampleFix":"// before\nvideojs.dom.hasClass(el, 'vjs-playing vjs-has-started');\n// after\n['vjs-playing', 'vjs-has-started'].every(c => videojs.dom.hasClass(el, c));","handlingStrategy":"validation","validationCode":"function hasClassSafe(el, className) {\n  if (typeof className !== 'string' || className.indexOf(' ') >= 0) {\n    throw new TypeError('className must be a single token with no spaces');\n  }\n  return videojs.dom.hasClass(el, className);\n}","typeGuard":"function isSingleClassName(c) {\n  return typeof c === 'string' && c.length > 0 && c.indexOf(' ') < 0;\n}","tryCatchPattern":null,"preventionTips":["Pass one class token at a time to hasClass.","For multi-class checks, split on whitespace and use .every().","Use addClass/removeClass for compound class strings (they already split on whitespace)."],"tags":["dom","classlist","validation","api-misuse"],"backgroundTag":null,"analyzedSha":"c3a7e0e6d20cf5400c9afbee29965fe4dff393c2","analyzedAt":"2026-08-13T04:20:15.471Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}