OrchardCMS/OrchardCore · error · Error

Syntax error, unrecognized expression:

Error message

Syntax error, unrecognized expression: 

What it means

Same Sizzle.error throw as the full build: Sizzle throws new Error('Syntax error, unrecognized expression: ' + msg) when a selector string is not valid per its grammar. In jquery.slim.js this is the entry point for all unrecognized-expression errors from $(), find(), filter(), etc.

Solutions

  1. Guard against empty/undefined selector strings before calling $()
  2. Escape special characters with CSS.escape or manual backslash escaping
  3. Correct the selector syntax (quote attribute values, balance brackets)
  4. Log the offending selector to identify the dynamic source

Example fix

// before
$(selector); // selector === ''
// after
if (typeof selector === 'string' && selector.trim()) { $(selector); }
Defensive patterns

Strategy: validation

Validate before calling

function isSafeSelector(sel) { return typeof sel === 'string' && sel.trim().length > 0 && /^[A-Za-z0-9_#.:\[\]"'=~|^$*>+~\s\-,(\\)-]+$/.test(sel); }

Type guard

function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }

Try / catch

try { $(sel).find(childSel); } catch (e) { if (e.message.startsWith('Syntax error, unrecognized expression')) { console.error('Invalid selector:', sel); } else { throw e; } }

Prevention

When it happens

Trigger: $('') or other empty/invalid selector strings; unbalanced brackets/parens; unescaped metacharacters (., :, [, ]) in ids or attribute selectors; invalid pseudo-selectors like :unknown.

Common situations: Building selectors from dynamic/empty values; ASP.NET-generated ids containing dots used unescaped in jQuery selectors; typos in pseudo-classes; user-supplied filter expressions.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/198bc0a9262ea8a5. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.4.1/jquery.slim.js:1560

		val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
			fn( elem, name, !documentIsHTML ) :
			undefined;

	return val !== undefined ?
		val :
		support.attributes || !documentIsHTML ?
			elem.getAttribute( name ) :
			(val = elem.getAttributeNode(name)) && val.specified ?
				val.value :
				null;
};

Sizzle.escape = function( sel ) {
	return (sel + "").replace( rcssescape, fcssescape );
};

Sizzle.error = function( msg ) {
	throw new Error( "Syntax error, unrecognized expression: " + msg );
};

/**
 * Document sorting and removing duplicates
 * @param {ArrayLike} results
 */
Sizzle.uniqueSort = function( results ) {
	var elem,
		duplicates = [],
		j = 0,
		i = 0;

	// Unless we *know* we can detect duplicates, assume their presence
	hasDuplicate = !support.detectDuplicates;
	sortInput = !support.sortStable && results.slice( 0 );
	results.sort( sortOrder );

	if ( hasDuplicate ) {

View on GitHub (pinned to 4306c0717f)