{"record":{"id":"3e2a6464cbd8151f","repo":"dotnet/AspNetCore.Docs","slug":"syntax-error-unrecognized-expression-msg-3e2a64","errorCode":null,"errorMessage":"Syntax error, unrecognized expression: ${msg}","messagePattern":"Syntax error, unrecognized expression: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/jquery-2.2.0.js","lineNumber":1463,"sourceCode":"        }\n    \n        var fn = Expr.attrHandle[ name.toLowerCase() ],\n            // Don't get fooled by Object.prototype properties (jQuery #13807)\n            val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?\n                fn( elem, name, !documentIsHTML ) :\n                undefined;\n    \n        return val !== undefined ?\n            val :\n            support.attributes || !documentIsHTML ?\n                elem.getAttribute( name ) :\n                (val = elem.getAttributeNode(name)) && val.specified ?\n                    val.value :\n                    null;\n    };\n    \n    Sizzle.error = function( msg ) {\n        throw new Error( \"Syntax error, unrecognized expression: \" + msg );\n    };\n    \n    /**\n     * Document sorting and removing duplicates\n     * @param {ArrayLike} results\n     */\n    Sizzle.uniqueSort = function( results ) {\n        var elem,\n            duplicates = [],\n            j = 0,\n            i = 0;\n    \n        // Unless we *know* we can detect duplicates, assume their presence\n        hasDuplicate = !support.detectDuplicates;\n        sortInput = !support.sortStable && results.slice( 0 );\n        results.sort( sortOrder );\n    \n        if ( hasDuplicate ) {","sourceCodeStart":1445,"sourceCodeEnd":1481,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/mvc/controllers/testing/samples/3.x/TestingControllersSample/src/TestingControllersSample/wwwroot/js/jquery-2.2.0.js#L1445-L1481","documentation":"Identical guard to error 3 in the 3.x sample's jquery-2.2.0.js: Sizzle.error fires for any unparseable selector passed to jQuery's selector APIs, appending the offending expression.","triggerScenarios":"Invalid selectors ($('[unclosed'), unescaped metacharacters in ids ($('#a.b')), malformed HTML parsed as selector.","commonSituations":"Dynamic selectors from data; ids with dots/colons/brackets; unsupported pseudo-classes.","solutions":["Escape metacharacters with $.escapeSelector (3.x) or manual escaping.","Use document.getElementById and wrap with $().","Validate/sanitize user-supplied selector input."],"exampleFix":"// before\n$('#user.email'); // throws\n// after\n$('#' + $.escapeSelector('user.email'));","handlingStrategy":"validation","validationCode":"function safeIdSelector(id) {\n  return '#' + (window.jQuery && jQuery.escapeSelector ? jQuery.escapeSelector(id) : id.replace(/([!\\\"#$%&'()*+,./:;<=>?@[\\]^`{|}~])/g, '\\\\$1'));\n}\n$(safeIdSelector(dynamicId)).hide();","typeGuard":"function looksLikeValidSelector(s) {\n  if (typeof s !== 'string' || s.length === 0) return false;\n  try { $(s); return true; } catch (e) { return false; }\n}","tryCatchPattern":"try {\n  return $(userSelector);\n} catch (e) {\n  if (/Syntax error, unrecognized expression/.test(e.message)) {\n    console.warn('Invalid selector:', userSelector);\n    return $();\n  }\n  throw e;\n}","preventionTips":["Use document.getElementById and wrap with $().","Escape metacharacters with $.escapeSelector.","Never interpolate raw user input into a selector."],"tags":["jquery","sizzle","selector","css","escaping"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}