JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css">
<h1 id="qunit-header">Unit tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
JavaScript
/*
A valid unquoted attribute value in HTML is any string of text that is not the empty string, and that doesn’t contain spaces, tabs, line feeds, form feeds, carriage returns, ", ', `, =, <, or >.
The space characters, for the purposes of this specification, are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), U+000A LINE FEED (LF), U+000C FORM FEED (FF), and U+000D CARRIAGE RETURN (CR).
*/
function v(value) {
// returns true if valid, false if invalid
// '\u0009' === '\t'
// '\u0020' === ' '
// '\u000A' === '\n'
// '\u000C' === '\f'
// '\u000D' === '\r'
return /^[^ \t\n\f\r"'`=<>]+$/.test(value);
}
module('Unquoted attribute values in HTML');
test('Invalid', function() {
equals(v(''), false, 'empty string');
equals(v('foo"bar'), false);
equals(v('foo\'bar'), false);
equals(v('foo`bar'), false);
equals(v('foo=bar'), false);
equals(v('foo<bar'), false);
equals(v('foo>bar'), false);
});
test('Valid', function() {
equals(v('foo-bar'), true);
equals(v('foo:bar'), true);
equals(v('fuubar'), true);
});
test('Whitespace', function() {
// Disallowed
equals(v('foo\u0020bar'), false, 'U+0020 SPACE');
// equals(v('foo\u0009bar', false, 'U+0009 CHARACTER TABULATION (tab)'); // '\t'
equals(v('foo\u000abar'), false, 'U+000A LINE FEED (LF)'); // '\n'
equals(v('foo\u000cbar'), false, 'U+000C FORM FEED (FF)'); // '\f'
equals(v('foo\u000dbar'), false, 'U+000D CARRIAGE RETURN (CR)'); // '\r'
// Allowed
equals(v('foo\u000bbar'), true, 'U+000B VERTICAL TAB'); // '\v'
equals(v('foo\u00a0bar'), true, 'U+00A0 NO-BREAK SPACE');
equals(v('foo\u2000bar'), true, 'U+2000 EN QUAD');
equals(v('foo\u2001bar'), true, 'U+2001 EM QUAD');
equals(v('foo\u2002bar'), true, 'U+2002 EN SPACE');
equals(v('foo\u2003bar'), true, 'U+2003 EM SPACE');
equals(v('foo\u2004bar'), true, 'U+2004 THREE-PER-EM SPACE');
equals(v('foo\u2005bar'), true, 'U+2005 FOUR-PER-EM SPACE');
...