{"record":{"id":"1927ed3c75891eab","repo":"twigphp/Twig","slug":"unexpected-end-of-file-unclosed-verbatim-block","errorCode":null,"errorMessage":"Unexpected end of file: Unclosed \"verbatim\" block.","messagePattern":"Unexpected end of file: Unclosed \"verbatim\" block\\.","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/Lexer.php","lineNumber":487,"sourceCode":"                while ($i + 1 < $length && ctype_digit($str[$i + 1]) && $str[$i + 1] < '8' && \\strlen($octal) < 3) {\n                    $octal .= $str[++$i];\n                }\n                $result .= \\chr(octdec($octal) % 256);\n            } else {\n                trigger_deprecation('twig/twig', '3.12', 'Character \"%s\" should not be escaped; the \"\\\" character is ignored in Twig 3 but will not be in Twig 4. Please remove the extra \"\\\" character at position %d in \"%s\" at line %d.', $nextChar, $i + 1, $this->source->getName(), $this->lineno);\n                $result .= $nextChar;\n            }\n\n            ++$i;\n        }\n\n        return $result;\n    }\n\n    private function lexRawData(): void\n    {\n        if (!preg_match($this->regexes['lex_raw_data'], $this->code, $match, \\PREG_OFFSET_CAPTURE, $this->cursor)) {\n            throw new SyntaxError('Unexpected end of file: Unclosed \"verbatim\" block.', $this->lineno, $this->source);\n        }\n\n        $offset = $this->cursor;\n        $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor);\n        $this->moveCursor($text.$match[0][0]);\n\n        // trim?\n        if (isset($match[1][0])) {\n            if ($this->options['whitespace_trim'] === $match[1][0]) {\n                // whitespace_trim detected ({%-, {{- or {#-)\n                $text = rtrim($text);\n            } else {\n                // whitespace_line_trim detected ({%~, {{~ or {#~)\n                // don't trim \\r and \\n\n                $text = rtrim($text, \" \\t\\0\\x0B\");\n            }\n        }\n","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Lexer.php#L469-L505","documentation":"The Lexer reached end of file while in RAW data state, meaning a `{% verbatim %}` block was opened but its `{% endverbatim %}` tag was never found. lexRawData scans for the closing tag; if the regex fails to match, the block is unclosed.","triggerScenarios":"A template contains `{% verbatim %}` without a matching `{% endverbatim %}` before EOF, e.g. `{% verbatim %}<div>{{ raw }}</div>` with the end tag accidentally deleted or placed after an `include` boundary.","commonSituations":"Documenting other template engines inside verbatim blocks and forgetting the closer; conditional includes where the `{% endverbatim %}` lives in a different partial than the opener; minifiers or build steps stripping what looks like a stray tag.","solutions":["Add the missing `{% endverbatim %}` before the end of the template.","Keep verbatim open/close pairs within the same template file — they cannot span includes.","Search the project for `{% verbatim %}` occurrences and verify each has a counterpart.","Note Twig 3.x also supports the shorter `{% raw %}` tag; mixing raw/verbatim spellings for open/close is invalid."],"exampleFix":"// before\n{% verbatim %}\n<div>{{ not_twig }}</div>\n\n// after\n{% verbatim %}\n<div>{{ not_twig }}</div>\n{% endverbatim %}","handlingStrategy":"validation","validationCode":"if (substr_count($code, '{% verbatim %}') + substr_count($code, '{% raw %}') !==\n    substr_count($code, '{% endverbatim %}') + substr_count($code, '{% endraw %}')) {\n    throw new \\InvalidArgumentException('Unbalanced verbatim/raw tags');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $twig->parse(new \\Twig\\Source($code, $name));\n} catch (\\Twig\\Error\\SyntaxError $e) {\n    log('Unclosed verbatim block: '.$e->getMessage());\n}","preventionTips":["Always keep verbatim/raw open and close tags in the same file.","Use consistent spelling (raw vs verbatim) for both tags.","Watch for minifiers stripping {% endraw %} tags."],"tags":["lexer","verbatim","unclosed-block","twig"],"backgroundTag":"unclosed-verbatim-block","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}