[3.0] Stop every page erroring when a member has a gallery avatar - #9440
Open
albertlast wants to merge 1 commit into
Open
[3.0] Stop every page erroring when a member has a gallery avatar#9440albertlast wants to merge 1 commit into
albertlast wants to merge 1 commit into
Conversation
Avatar's last resort for finding a file is to take the path out of the url and look for it under the avatar directories. Working out what to strip means reading the forum's own path: preg_quote(Url::create(Config::$boardurl)->path, '~') Url::$path is typed with no default, so a forum installed at the root of its domain does not have one to read, and reading it throws rather than giving back an empty string. Saving a profile with the avatar set to a gallery image is a fatal error on any such install: Typed property SMF\Url::$path must not be accessed before initialization -- Avatar.php:539 Reading it with ?? '' leaves the replacement matching nothing, which is what it did before whenever the forum lived at the root of a path. Signed-off-by: Mathias Alberts <mathiaspapealbert@hotmail.com> Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
This was referenced Aug 9, 2026
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.
Description
On a forum installed at the root of its domain, one member with a prepackaged (gallery)
avatar takes the whole forum down. Every page that renders that member is a 500 — the board
index, because of the "last post by" line, as much as their profile.
Avatar's last resort for locating a file is to take the path out of the url and look forit under the avatar directories, which means reading the forum's own path so it can be
stripped:
Url::$pathis typed with no default. A forum at the root of its domain has no path, so theproperty was never assigned, and reading it throws rather than giving back
''. A forumunder a path prefix never reaches this.
That branch is exactly where a gallery avatar lands: the column holds a bare
Oxygen/cards.png, which is not a valid url, so the resolver falls through to it everytime.
(The neighbouring
!empty($url->path)guard three lines up is fine —empty()andisset()on an uninitialised typed property answer without raising. It is the direct readthat goes wrong.)
Reading it as
?? ''leavespreg_replace()with a pattern of~^~u, which matches theempty string at position 0 and replaces nothing — exactly what the call already did on
every forum that does live under a path prefix. Nothing changes for those; the rooted
case stops throwing.
Checked
http://localhost:8080(no path), withsmf_members.avatarset toOxygen/cards.pngforone member:
Saving a profile with a gallery avatar chosen goes from a 500 to "Your profile has been
updated successfully", and
smf_log_errorsstays empty across the lot. Members with anuploaded avatar, a gravatar, and no avatar are unaffected either way.
Noticed while here, not fixed
With the fatal gone, a gallery avatar still does not stick:
smf_members.avatariscleared on save, and a value put there by hand renders as
default.png.Profile::setAvatarServerStored()puts the right string intonew_data(verified:Oxygen/cards.png), butUser::updateMemberData()round-trips it throughnew Avatar(original_url: …), which cannot turn a bare filename back into a url. That is aseparate change and wants its own PR.
Issues References (Fixes|Related|Closes)
n/a