mirror of
https://github.com/unraid/webgui.git
synced 2026-01-01 23:20:35 -06:00
c364912d08fd0c288d2d23e7e79cb4eecd2c2e57
The error occurred because of how searchLink() is called on line 49:
if ($support = searchLink($info, $url) ?: searchLink($info, newurl($url))) {
Here's the sequence of events that caused the issue:
1. First call: searchLink($info, $url) - This works fine if $info contains the JSON data from
/tmp/community.applications/tempFiles/templates.json
2. If first call returns falsy: The ?: operator (shorthand ternary) triggers the second call:
searchLink($info, newurl($url))
3. The problem: When the first searchLink() returns null or false, PHP's ?: operator evaluates
the second expression. However, if $info itself is null (which can happen if the JSON file
doesn't exist or is empty - see line 19 where readJson() returns [] for missing files), then
searchLink(null, newurl($url)) is called.
4. The crash: Inside searchLink(), when $db is null, calling count($db) throws the TypeError
because count() requires an array or Countable object, not null.
Root causes:
- The JSON file at /tmp/community.applications/tempFiles/templates.json might not exist or could
be corrupted
- The readJson() function returns an empty array [] for missing files, but if the JSON decode
fails, it could return null
- The code wasn't defensive against null values being passed to searchLink()
The fix adds is_array($db) check to ensure we only attempt to count when we have a valid array.
Unraid webgui repo
Structure
The emhttp, etc, sbin, and src dirs in this repo are extracted to the /usr/local/ directory when an Unraid release is built.
Contributions
Please be aware that there is a fairly high barrier to entry when working on the Unraid webgui. It has grown organically over the years and you will need to do quite a bit of reverse engineering to understand it.
If you choose to proceed, clone this repo locally, test edits by copying the changes to your server, then submit a PR to https://github.com/unraid/webgui when fully tested.
Be sure to describe (in the Unraid forum, a GitHub issue, or the GitHub PR) the problem/feature you are working on and explain how the proposed change solves it.
We recommend using VS Code with the following plugins:
- Install natizyskunk.sftp and use .vscode/sftp-template.json as a template for creating your personalized sftp.json file to have VS Code upload files to your server when they are saved. Your personalized sftp.json file is blocked by .gitignore so it should never be included in your PR.
- Install bmewburn.vscode-intelephense-client and when reasonable, implement its recommendations for PHP code.
- Install DavidAnson.vscode-markdownlint and when reasonable, implement its recommendations for markdown code.
- Install foxundermoon.shell-format and timonwong.shellcheck and when reasonable, implement their recommendations when making changes to bash scripts.
- Install esbenp.prettier-vscode and when reasonable, use it for formatting files.
Description
Languages
JavaScript
53.5%
PHP
31.5%
Shell
6.9%
CSS
5.8%
HTML
2.2%