Skip to content

Commit 20d1886

Browse files
ondrejmirtesclaude
andcommitted
Reproduce php_strip_whitespace() byte for byte in the native symbol scan
The native stripper in front of SymbolFinderInFiles' cleaner removed comments with a hand scanner and copied everything else through, on the claim that whitespace does not matter downstream. Both halves were wrong: - inside {$...} / ${...} interpolation the lexer is in script mode, so a nested "..." is a separate string; the scanner ended the outer string at it, lost `class HashInterp` after "{$a["#"]}" and invented a class inside "{$a["/*"]}"; - zend_strip() collapses whitespace tokens, newlines included, and after a heredoc's closing label writes the next token verbatim - a comment too - followed by "\n". The cleaner's // handling skips to the next newline and its quote pairing is naive, so which symbols survive depends on exactly those bytes. Port the lexer rules zend_strip() can observe instead (states and state stack for strings, interpolation, heredoc/nowdoc, variable offsets and property lookups, brace nesting; the tokens that keep whitespace or comments inside - casts, `yield from`; the skipped shebang line) and mirror zend_strip() on top. The output is byte-identical to php_strip_whitespace() over the repository and vendor/ and over ~40,000 fuzzed and mutated inputs, with short_open_tag on and off. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
1 parent 7af8b74 commit 20d1886

3 files changed

Lines changed: 917 additions & 149 deletions

File tree

‎turbo-ext/src/SymbolFinderInFiles.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void SymbolFinderInFiles::scan(bool supportsEnums)
114114

115115
if (source.empty()) return;
116116

117-
CommentStripper stripper(source.data(), source.size(), shortOpenTagEnabled());
117+
CommentStripper stripper(source.data(), source.size(), shortOpenTagEnabled(), skipShebangEnabled());
118118
stripper.strip(stripped);
119119

120120
if (stripped.empty()) return;

0 commit comments

Comments
 (0)