{"record":{"id":"78d89bd182921fcb","repo":"OrchardCMS/OrchardCore","slug":"syntax-error-unrecognized-expression-jquery","errorCode":null,"errorMessage":"Syntax error, unrecognized expression: ","messagePattern":"Syntax error, unrecognized expression: ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.5.1/jquery.js","lineNumber":1677,"sourceCode":"\t\tval = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?\n\t\t\tfn( elem, name, !documentIsHTML ) :\n\t\t\tundefined;\n\n\treturn val !== undefined ?\n\t\tval :\n\t\tsupport.attributes || !documentIsHTML ?\n\t\t\telem.getAttribute( name ) :\n\t\t\t( val = elem.getAttributeNode( name ) ) && val.specified ?\n\t\t\t\tval.value :\n\t\t\t\tnull;\n};\n\nSizzle.escape = function( sel ) {\n\treturn ( sel + \"\" ).replace( rcssescape, fcssescape );\n};\n\nSizzle.error = function( msg ) {\n\tthrow new Error( \"Syntax error, unrecognized expression: \" + msg );\n};\n\n/**\n * Document sorting and removing duplicates\n * @param {ArrayLike} results\n */\nSizzle.uniqueSort = function( results ) {\n\tvar elem,\n\t\tduplicates = [],\n\t\tj = 0,\n\t\ti = 0;\n\n\t// Unless we *know* we can detect duplicates, assume their presence\n\thasDuplicate = !support.detectDuplicates;\n\tsortInput = !support.sortStable && results.slice( 0 );\n\tresults.sort( sortOrder );\n\n\tif ( hasDuplicate ) {","sourceCodeStart":1659,"sourceCodeEnd":1695,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/jquery-3.5.1/jquery.js#L1659-L1695","documentation":"Sizzle, jQuery's selector engine, throws this when a selector expression cannot be parsed or is not supported. jQuery.typed access like $('#id'), $('.class') is fine, but malformed strings (unbalanced brackets/quotes) or unsupported pseudo-selectors reach Sizzle.error. The thrown message appends the offending selector text.","triggerScenarios":"Calling $(expr) / find(expr) / closest(expr) with a syntactically invalid selector (e.g. 'div[', \"a[href='x]\"), an unknown custom pseudo-class like :mywidget, or passing a non-string non-element object that jQuery cannot interpret as a selector.","commonSituations":"Building selectors by string concatenation and injecting unescaped user data with quotes/brackets; typos in custom :pseudo names after plugins were removed; using selectors valid in querySelectorAll polyfills but not in Sizzle's grammar; dynamically generated selectors from config values.","solutions":["Log the selector at the throw site: the text after 'Syntax error, unrecognized expression: ' identifies the bad input; validate/escape it before passing to $().","Sanitize or reject user-supplied fragments before composing selectors (escape quotes and brackets, or use explicit APIs like .filter(fn) instead of dynamic selector strings).","Replace unsupported custom pseudo-selectors with jQuery plugin definitions ($.expr.pseudos) or plain filter functions.","Prefer programmatic APIs (e.g. document.getElementById result passed into $(node)) over string interpolation when values come from user input."],"exampleFix":"// before\n$(\"[data-x='\" + userInput + \"']\"); // throws if userInput contains ' or ]\n// after\n$(\"[data-x]\").filter(function(){ return $(this).data('x') === userInput; });","handlingStrategy":"validation","validationCode":"function isValidSelector(sel) {\n  if (typeof sel !== 'string' || !sel.trim()) return false;\n  try { document.createDocumentFragment().querySelector(sel); } catch (e) { return false; }\n  return true;\n}\n// call $(sel) only if isValidSelector(sel)","typeGuard":"function isSelectorString(v) { return typeof v === 'string' && /^[\\w\\s.#>\\-\\[\\]:()\"'=,~+*|^$@]*$/.test(v); }","tryCatchPattern":"try { $(sel); } catch (e) { if (e.message.startsWith('Syntax error, unrecognized expression')) { console.error('Bad selector:', sel); return $(); } throw e; }","preventionTips":["Escape dynamic fragments with jQuery.escapeSelector before composing selectors.","Prefer .filter(fn) over interpolated selector strings for user-derived values.","Never interpolate raw quotes/brackets from user input into attribute selectors.","Pre-test dynamically generated selectors with querySelector in a try/catch during development."],"tags":["jquery","sizzle","selector","syntax"],"backgroundTag":"invalid-argument-format","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}