{"record":{"id":"efba73c3108c415f","repo":"symfony/css-selector","slug":"invalid-series-s","errorCode":null,"errorMessage":"Invalid series: \"%s\".","messagePattern":"Invalid series: \"(.+?)\"\\.","errorType":"exception","errorClass":"ExpressionErrorException","httpStatus":null,"severity":"error","filePath":"XPath/Extension/FunctionExtension.php","lineNumber":53,"sourceCode":"        return [\n            'nth-child' => $this->translateNthChild(...),\n            'nth-last-child' => $this->translateNthLastChild(...),\n            'nth-of-type' => $this->translateNthOfType(...),\n            'nth-last-of-type' => $this->translateNthLastOfType(...),\n            'contains' => $this->translateContains(...),\n            'lang' => $this->translateLang(...),\n        ];\n    }\n\n    /**\n     * @throws ExpressionErrorException\n     */\n    public function translateNthChild(XPathExpr $xpath, FunctionNode $function, bool $last = false, bool $addNameTest = true): XPathExpr\n    {\n        try {\n            [$a, $b] = Parser::parseSeries($function->getArguments());\n        } catch (SyntaxErrorException $e) {\n            throw new ExpressionErrorException(\\sprintf('Invalid series: \"%s\".', implode('\", \"', $function->getArguments())), 0, $e);\n        }\n\n        $xpath->addStarPrefix();\n        if ($addNameTest) {\n            $xpath->addNameTest();\n        }\n\n        if (0 === $a) {\n            return $xpath->addCondition('position() = '.($last ? 'last() - '.($b - 1) : $b));\n        }\n\n        if ($a < 0) {\n            if ($b < 1) {\n                return $xpath->addCondition('false()');\n            }\n\n            $sign = '<=';\n        } else {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/symfony/css-selector/blob/08e2905152a39cf3fd1745d83f8c483e258887d9/XPath/Extension/FunctionExtension.php#L35-L71","documentation":"ExpressionErrorException thrown by FunctionExtension::translateNthChild when Parser::parseSeries cannot extract valid (a, b) coefficients from the arguments of :nth-child(), :nth-last-child(), :nth-of-type(), or :nth-last-of-type(). parseSeries throws SyntaxErrorException for malformed An+B expressions; this wraps it with the offending argument list.","triggerScenarios":"Translating a selector like li:nth-child(odd extra), li:nth-child(n+b+1), li:nth-child(1.5n), or an empty :nth-child() — any argument that is not a valid 'an+b' series — via Translator::cssToXPath.","commonSituations":"Typos in hand-written selectors, localized 'odd/even' spelled differently, user-supplied selectors with invalid formulas, passing values like 'even,' with stray commas.","solutions":["Fix the selector's nth expression to a valid An+B form: integer, 'odd', 'even', 'an', 'an+b', '-an+b', 'n', '2n+1', etc.","Catch Symfony\\Component\\CssSelector\\Exception\\ExpressionErrorException around the translation call.","Validate the nth argument with a regex such as /^([+-]?\\d*n)?\\s*([+-]\\s*\\d+)?$/ before translating.","Upgrade the library — some edge-case series parse failures were fixed in newer css-selector releases."],"exampleFix":"// before\n'li:nth-child(2 n + 1)'\n// after\n'li:nth-child(2n+1)'","handlingStrategy":"validation","validationCode":"function isValidAnB(?string $expr): bool {\n    return null !== $expr && (bool) preg_match('/^([+-]?\\d*n)?\\s*([+-]\\s*\\d+)?$|^odd$|^even$/i', trim($expr));\n}\n// validate each :nth-child() argument before cssToXPath","typeGuard":null,"tryCatchPattern":"try {\n    $xpath = $translator->cssToXPath($css);\n} catch (\\Symfony\\Component\\CssSelector\\Exception\\ExpressionErrorException $e) {\n    if (str_starts_with($e->getMessage(), 'Invalid series:')) {\n        // fix or reject the nth expression\n    }\n}","preventionTips":["Only emit canonical An+B forms: 'odd', 'even', '2n+1', '-n+3'.","Trim whitespace inside nth expressions.","Validate programmatically generated nth values against the An+B regex.","Keep css-selector current; parseSeries edge cases get fixed over time."],"tags":["css-selector","nth-child","invalid-expression"],"backgroundTag":"invalid-argument-format","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"}