OrchardCMS/OrchardCore · error · Error

Syntax error, unrecognized expression:

Error message

Syntax error, unrecognized expression: 

What it means

Identical to the jquery.js case: Sizzle (the selector engine bundled in jquery.slim.js) throws this when a selector string fails to parse. The empty message suffix means the offending expression was an empty string. jquery.slim.js shares the Sizzle code path, so any $() / .find() / .filter() call with a syntactically invalid (or empty, when routed through selector parsing) selector reaches Sizzle.error.

Solutions

  1. Validate the selector before use: if (typeof sel !== 'string' || !sel.trim()) skip or return an empty collection.
  2. Fix the malformed selector string to conform to supported CSS selector syntax.
  3. Instrument Sizzle.error or wrap $() to log the offending selector value to identify the producer.
  4. Update third-party plugins that pass invalid selectors to a jQuery-3-compatible version.

Example fix

// before
$(location.hash); // empty hash yields $("")

// after
var hash = location.hash;
var $el = (hash && hash.length > 1) ? $(hash) : $();
Defensive patterns

Strategy: validation

Validate before calling

function usableSelector(sel) {
  return typeof sel === 'string' && sel.trim().length > 0;
}
// usage: var $el = usableSelector(hash) ? $(hash) : $();

Type guard

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

Try / catch

try {
  $target = $(sel);
} catch (e) {
  if (e.message.indexOf('unrecognized expression') !== -1) {
    console.warn('Bad selector:', JSON.stringify(sel));
    $target = $();
  } else throw e;
}

Prevention

When it happens

Trigger: $("") or an empty string reaching selector tokenization; malformed selectors like "#id>>", ".a[" or unbalanced quotes passed to $(), .find(), .closest(), .is(), .not(), :has()/:not() arguments; string-built selectors from empty variables.

Common situations: Dynamic selectors sourced from data attributes, query strings, or CMS-rendered values that are empty; slim build used where full build previously masked behavior; plugins constructing selectors via concatenation.

Related errors


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

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.6.0/jquery.slim.js:1681

		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)