Repository navigation
Code smells of #283 (3/3): HtaccessHelper reads and writes the file once (C15) - #325
Merged
Merged
Conversation
…e it back once (issue #283, C15) The marker state machines of extract() and insert() are one parser, load(), and one writer, store(). Every change reads the file once instead of twice. The output is byte for byte that of the old code for a file with none or one section, with the same results and log messages; a file with several sections now gets one, not the merged section once for each. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFJFMNpwNryanqvRcQvqDc
…hich is gone Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFJFMNpwNryanqvRcQvqDc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 3 of 3 for #283. Stacked on #324 (which is stacked on #323): the base is that PR's branch, so retarget to
mainonce the ones below have merged.Problem
HtaccessHelperfound its block section with two copies of the BEGIN/END marker state machine:extract()to read it,insert()to replace it. Each change read and scanned the file twice.Change
load()reads the file once intobefore/section/after(plusfoundandunterminated).store()writes it back once, with the new section where the old one was, or at the top followed by an empty line if there was none.parseSection()is now a pure function of the section's lines, with no file access. Every change reads the file once and writes it once.extract()andinsert()are gone.Behaviour
I recorded what the old code does for 14 file shapes (missing, empty, no or one section, no trailing newline, CRLF, legacy form, hand-written lines, unterminated BEGIN, other tools' markers, and so on) times 9 operations (deny, undeny, upgrade, 403 message, remove addresses, reads), 126 cases in all, then compared the new code. 117 are byte for byte identical, including return values and log messages.
The nine that differ are all the file with two BFStop sections. A change used to write the merged section once for each old section, so the file kept two copies. It now gets one, at the first section's position, with the addresses of both and the lines between and around them kept. A file like that is not meant to exist, and
testSeveralSectionsBecomeOnecovers it. A stray# ENDline outside a section is now left as an ordinary line; the old code replaced it with a section.Testing
The comparison above ran outside Joomla, with stubs for
Log,FactoryandUri.HtaccessHelperTestand the Apache job need a Joomla tree (JOOMLA_ROOT) that this environment doesn't have, so CI is the first run of those.php -lis clean; phpstan is not run here for the same reason.Generated by Claude Code