{"record":{"id":"2d930bbce6324363","repo":"louis-e/arnis","slug":"syntax-error-unrecognized-expression","errorCode":null,"errorMessage":"Syntax error, unrecognized expression: ","messagePattern":"Syntax error, unrecognized expression: ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/gui/js/libs/jquery-1.9.1.js","lineNumber":4421,"sourceCode":"\t\tsetDocument( elem );\n\t}\n\n\tif ( !documentIsXML ) {\n\t\tname = name.toLowerCase();\n\t}\n\tif ( (val = Expr.attrHandle[ name ]) ) {\n\t\treturn val( elem );\n\t}\n\tif ( documentIsXML || support.attributes ) {\n\t\treturn elem.getAttribute( name );\n\t}\n\treturn ( (val = elem.getAttributeNode( name )) || elem.getAttribute( name ) ) && elem[ name ] === true ?\n\t\tname :\n\t\tval && val.specified ? val.value : null;\n};\n\nSizzle.error = function( msg ) {\n\tthrow new Error( \"Syntax error, unrecognized expression: \" + msg );\n};\n\n// Document sorting and removing duplicates\nSizzle.uniqueSort = function( results ) {\n\tvar elem,\n\t\tduplicates = [],\n\t\ti = 1,\n\t\tj = 0;\n\n\t// Unless we *know* we can detect duplicates, assume their presence\n\thasDuplicate = !support.detectDuplicates;\n\tresults.sort( sortOrder );\n\n\tif ( hasDuplicate ) {\n\t\tfor ( ; (elem = results[i]); i++ ) {\n\t\t\tif ( elem === results[ i - 1 ] ) {\n\t\t\t\tj = duplicates.push( i );\n\t\t\t}","sourceCodeStart":4403,"sourceCodeEnd":4439,"githubUrl":"https://github.com/louis-e/arnis/blob/34048924d9365795fb0d832e76140a3fbdc413d9/src/gui/js/libs/jquery-1.9.1.js#L4403-L4439","documentation":"Sizzle (jQuery 1.9.1's CSS selector engine) throws this when passed a selector string it cannot parse or that matches no known expression syntax. jQuery 1.x funnels all selector parsing through Sizzle; an empty, malformed, or unsupported selector reaches Sizzle.error and raises this Error. It is thrown from the parser itself, so it fires synchronously wherever jQuery(cssSelector) or .find()/.filter() is called.","triggerScenarios":"Calling jQuery() / $(selector) / .find() / .is() with: an empty string ('' or undefined coerced), unbalanced quotes/parens/brackets (e.g. \"div[title='x\"), unknown pseudo-selectors (:foo where foo isn't defined and no plugin provides it), or a non-string like a plain object that stringifies to garbage in jQuery 1.9's stricter parser.","commonSituations":"Selectors built by string concatenation where a variable is empty or undefined ($(frag)); upgrading from jQuery 1.8 to 1.9 which removed removed/changed pseudo-selectors (:contains without quotes, :radio[name=] edge cases, etc.); typos in custom pseudo-selector names; markup-derived attribute values containing quotes used inside selectors.","solutions":["Inspect the selector string logged in the error message (the part after 'unrecognized expression:') and fix the malformed portion — usually an unbalanced quote or bracket.","Guard for empty/undefined values before building selectors: only call $() when the interpolated variable is a non-empty string.","Replace pseudo-selectors removed or restricted in jQuery 1.9 (see the jQuery 1.9 upgrade guide) or quote string arguments, e.g. :contains(\"text\").","Use .filter(fn) with a predicate function instead of building complex attribute selectors from dynamic data.","If a plugin's custom pseudo-selector is missing, include/update the plugin (e.g. an updated Sizzle-compatible version)."],"exampleFix":"// before\n$(\"input[value=\" + userInput + \"]\").hide(); // userInput empty -> Syntax error, unrecognized expression: input[value=]\n// after\nif (userInput) {\n  $(\"input[value='\" + userInput.replace(/'/g, \"\\\\'\") + \"']\").hide();\n} else {\n  $(\"input\").hide();\n}","handlingStrategy":"validation","validationCode":"function isSafeSelector(sel) {\n  return typeof sel === \"string\" && sel.trim().length > 0 &&\n    !/[\"'](?![^\"']*[\"'])/.test(sel); // crude unbalanced-quote check\n}\nif (isSafeSelector(mySelector)) $(mySelector).hide();","typeGuard":"function isNonEmptyString(v) { return typeof v === \"string\" && v.trim().length > 0; }","tryCatchPattern":"try {\n  $(selector).doSomething();\n} catch (e) {\n  if (/unrecognized expression/.test(e.message)) {\n    console.warn(\"bad selector:\", JSON.stringify(selector));\n  } else { throw e; }\n}","preventionTips":["Never build selectors by naive string concatenation of unvalidated values.","Quote dynamic values inside attribute selectors: [attr='value'].","Consult the jQuery 1.9 upgrade guide when migrating; several pseudo-selectors changed.","Prefer .filter(fn) over complex dynamic selectors."],"tags":["jquery","sizzle","selector-syntax","frontend"],"backgroundTag":"invalid-css-selector","analyzedSha":"34048924d9365795fb0d832e76140a3fbdc413d9","analyzedAt":"2026-09-03T14:05:17.283Z","contentChangedAt":"2026-09-03T14:05:17.283Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}