Skip to content

Fix element booting, holder writes, db path names and invalid route expressions - #672

Open
samuelpatro wants to merge 2 commits into
octobercms:developfrom
samuelpatro:fix/halcyon-router-element-correctness
Open

samuelpatro wants to merge 2 commits into
octobercms:developfrom
samuelpatro:fix/halcyon-router-element-correctness

Conversation

@samuelpatro

@samuelpatro samuelpatro commented Aug 30, 2026

Copy link
Copy Markdown
Member

Four unrelated correctness bugs, one commit. Each has a test that fails on develop.

src/Element/ElementBase.php__construct() never called parent::__construct(), so Extendable::extendableConstruct() did not run: SomeElement::extend(fn) callbacks and $implement behaviors were ignored for constructed elements, but applied by __wakeup() for unserialized ones. Added the parent call. Test: tests/Element/ElementBaseTest.php (testExtendCallbackIsAppliedOnConstruction, testImplementedBehaviorIsApplied).

src/Element/ElementHolder.phpget() returned $touchedElements[$key] if present, so a value read once was returned forever even after $holder['key'] = 'new' wrote to $config. get() now reads $config and records the touch; added offsetUnset() that also clears the touch. Test: testHolderReturnsWrittenValueAfterRead.

src/Halcyon/Datasource/DbDatasource.phppathToFileName() used str_replace($dirName, '', $path), removing every occurrence: pages/pages/about.htmabout.htm. Now strips only a leading $dirName/. Test: tests/Halcyon/Datasource/DbDatasourceTest.php::testPathToFileNameStripsOnlyTheDirectoryPrefix.

src/Router/Router.php, src/Router/Rule.php — the preg_match on a :param|regex segment sat in try { } catch (Exception) { } with an empty catch. When the expression is invalid, PHP emits a warning; under Laravel's error handler that is an ErrorException, which was swallowed, leaving $valid = true (Router) or falling through to return true (Rule). A malformed route expression therefore matched any value. Both now treat the exception as a non-match. Tests: tests/Router/RouteTest.php (testInvalidParameterExpressionFailsClosed, ...OnRule) install a throwing error handler and assert the URL does not match.

…d route expressions

ElementBase never called Extendable::__construct, so extend() callbacks and $implement were ignored on construction but applied on unserialize. ElementHolder::get served a value cached by an earlier read after offsetSet had replaced it. DbDatasource::pathToFileName removed every occurrence of the directory name instead of the leading one. Router and Rule accepted a URL when a parameter expression threw instead of rejecting it.
@samuelpatro
samuelpatro marked this pull request as ready for review August 30, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant