{"record":{"id":"dfdb15bf0fd4add1","repo":"dotnet/AspNetCore.Docs","slug":"syntax-error-unrecognized-expression-msg-dfdb15","errorCode":null,"errorMessage":"Syntax error, unrecognized expression: ${msg}","messagePattern":"Syntax error, unrecognized expression: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"aspnetcore/mvc/views/tag-helpers/th-components/samples/RazorPagesSample/wwwroot/lib/jquery/jquery.js","lineNumber":1463,"sourceCode":"\t}\n\n\tvar fn = Expr.attrHandle[ name.toLowerCase() ],\n\t\t// Don't get fooled by Object.prototype properties (jQuery #13807)\n\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.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":1445,"sourceCodeEnd":1481,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/mvc/views/tag-helpers/th-components/samples/RazorPagesSample/wwwroot/lib/jquery/jquery.js#L1445-L1481","documentation":"jQuery's Sizzle selector engine throws via `Sizzle.error` when a selector string cannot be tokenized/parsed. The message is `'Syntax error, unrecognized expression: ' + msg`, surfacing the offending selector fragment.","triggerScenarios":"Passing a malformed selector to any jQuery DOM method (`$()`, `.find()`, `.filter()`, `.on()` with delegation, etc.). Examples: unbalanced brackets `$('div[')`, leading/trailing special chars, invalid pseudo-classes, unescaped attribute values containing meta-characters.","commonSituations":"Dynamically building selectors from user input that contains `#`, `.`, `[`, `:`; attribute selectors with quotes/brackets in the value; typos in class/ID selectors; using a CSS selector where an HTML string was intended.","solutions":["Escape meta-characters in dynamic values with `$.escapeSelector(value)` before interpolation.","Prefer attribute-value selectors with quotes: `$('[data-id=\"' + id + '\"]')` instead of `$('#' + id)` when id may contain dots.","Validate the selector before use, or use `.find()` / `.filter()` with a function for dynamic matching.","Check for balanced brackets and valid syntax; log the selector to find the malformed fragment in the error message."],"exampleFix":"// before\nvar $el = $('#' + userInput);  // fails if userInput has '.' or ':'\n\n// after\nvar $el = $('[id=\"' + $.escapeSelector(userInput) + '\"]');","handlingStrategy":"validation","validationCode":"function safeFind(selector, ctx) {\n  try { return $(selector, ctx); }\n  catch (e) {\n    if (/Syntax error/.test(e.message)) {\n      return ctx ? $(ctx).find(selector) : $();\n    }\n    throw e;\n  }\n}","typeGuard":"function isValidSelector(selector) {\n  try { document.createDocumentFragment().querySelector(selector); return true; }\n  catch (e) { return false; }\n}","tryCatchPattern":"try {\n  return $(selector);\n} catch (e) {\n  if (/Syntax error/.test(e.message)) {\n    console.warn('Bad selector:', selector);\n    return $(); // empty collection\n  }\n  throw e;\n}","preventionTips":["Escape dynamic values with `$.escapeSelector`.","Use quoted attribute selectors for user-derived IDs.","Prefer `.find()`/`.filter()` functions over string-built selectors."],"tags":["jquery","sizzle","selector","syntax-error"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}