{"record":{"id":"56298f64e6d2b31d","repo":"symfony/css-selector","slug":"attribute-matcher-operator-s-not-supported","errorCode":null,"errorMessage":"Attribute matcher operator \"%s\" not supported.","messagePattern":"Attribute matcher operator \"(.+?)\" not supported\\.","errorType":"exception","errorClass":"ExpressionErrorException","httpStatus":null,"severity":"error","filePath":"XPath/Translator.php","lineNumber":217,"sourceCode":"    /**\n     * @throws ExpressionErrorException\n     */\n    public function addPseudoClass(XPathExpr $xpath, string $pseudoClass): XPathExpr\n    {\n        if (!isset($this->pseudoClassTranslators[$pseudoClass])) {\n            throw new ExpressionErrorException(\\sprintf('Pseudo-class \"%s\" not supported.', $pseudoClass));\n        }\n\n        return $this->pseudoClassTranslators[$pseudoClass]($xpath);\n    }\n\n    /**\n     * @throws ExpressionErrorException\n     */\n    public function addAttributeMatching(XPathExpr $xpath, string $operator, string $attribute, ?string $value): XPathExpr\n    {\n        if (!isset($this->attributeMatchingTranslators[$operator])) {\n            throw new ExpressionErrorException(\\sprintf('Attribute matcher operator \"%s\" not supported.', $operator));\n        }\n\n        return $this->attributeMatchingTranslators[$operator]($xpath, $attribute, $value);\n    }\n\n    /**\n     * @return SelectorNode[]\n     */\n    private function parseSelectors(string $css): array\n    {\n        foreach ($this->shortcutParsers as $shortcut) {\n            $tokens = $shortcut->parse($css);\n\n            if ($tokens) {\n                return $tokens;\n            }\n        }\n","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/symfony/css-selector/blob/08e2905152a39cf3fd1745d83f8c483e258887d9/XPath/Translator.php#L199-L235","documentation":"Translator::addAttributeMatching() dispatches an attribute matcher operator (=, ^=, $=, *=, ~=, |=) to a handler in $this->attributeMatchingTranslators and throws ExpressionErrorException when the operator is unknown. The operator normally comes from parsed Attribute nodes, so valid CSS never triggers this — it is a guard for the extension/programmatic API.","triggerScenarios":"Calling addAttributeMatching() with an $operator string not among the registered matchers (e.g. '!==' or an empty string), typically from custom node construction or a test such as testAddAttributeMatchingClassNotExistsClass.","commonSituations":"Programmatic XPathExpr/Attribute node building with an invalid operator; custom selector dialects with new operators lacking a registered matcher; corrupted tokenization upstream.","solutions":["Use a standard CSS attribute operator: =, ^=, $=, *=, ~=, |=.","Register a custom attribute matching translator via Translator::extension() for non-standard operators.","Verify the operator value produced by the parser for the attribute selector in question."],"exampleFix":"// before\n$translator->addAttributeMatching($xpath, '!==', 'href', 'x'); // unknown operator, throws\n\n// after\n$translator->addAttributeMatching($xpath, '!=', 'href', 'x'); // only if registered, else use '=' and filter\n// safest: use a supported operator\n$translator->addAttributeMatching($xpath, '=', 'href', 'x');","handlingStrategy":"validation","validationCode":"const VALID_ATTR_OPS = ['=', '^=', '$=', '*=', '~=', '!=', '|='];\nif (!in_array($operator, self::VALID_ATTR_OPS, true)) {\n    throw new \\InvalidArgumentException(\"Invalid attribute operator: $operator\");\n}","typeGuard":null,"tryCatchPattern":"use Symfony\\Component\\CssSelector\\Exception\\ExpressionErrorException;\ntry {\n    $expr = $translator->addAttributeMatching($xpath, $op, $attr, $value);\n} catch (ExpressionErrorException $e) {\n    // coerce to '=' or skip the attribute condition\n}","preventionTips":["Only construct Attribute nodes with operators from the standard CSS set","Sanitize operators parsed from custom selector dialects","Cover each operator path with unit tests so regressions surface early"],"tags":["css-selector","xpath","attribute-selector","unsupported-operator"],"backgroundTag":"unsupported-enum-value","analyzedSha":"08e2905152a39cf3fd1745d83f8c483e258887d9","analyzedAt":"2026-09-14T11:41:28.509Z","contentChangedAt":"2026-09-14T11:41:28.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}