fix #1246 and #1415: settings save no longer corrupts config.php#1421
Open
nerun wants to merge 1 commit into
Open
fix #1246 and #1415: settings save no longer corrupts config.php#1421nerun wants to merge 1 commit into
nerun wants to merge 1 commit into
Conversation
…erwrites/corrupts config.php structure
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.
This is a robust fix for issues #1246 and #1415.
Issue
When using an external config.php based on the official config-sample.txt, saving settings from the UI can corrupt the config file and make Tiny File Manager fail with HTTP 500.
The official sample starts like this:
<?php /*This is valid PHP.
But the settings save mechanism appears to blindly overwrite the first three lines of config.php with:
So the opening /* of the comment block is removed, while the rest of the comment remains in the file.
Result after saving:
This makes config.php invalid PHP and Tiny File Manager no longer loads - HTTP 500.
Expected behavior
The settings save mechanism should not blindly replace the first three lines of config.php.
Fix adopted by this PR
Instead of blindly overwriting the first three lines of
config.php, this fix locates and replaces only the existing$CONFIG = ...;assignment line, leaving the rest of the file (including comments, blank lines, and any custom structure) completely untouched.Behavior:
$CONFIGalready exists: only that line is replaced with the updated value. All other lines, including comment blocks like/* ... */, remain exactly as they were.$CONFIGdoes not exist yet (e.g. a freshconfig.phpbased onconfig-sample.txt): the new$CONFIG = ...;line is inserted right after the opening<?phptag, without deleting or altering anything else in the file.<?phptag itself can't be matched for some unexpected reason, the new line is prepended along with<?php, still preserving the entire original content.This ensures the settings save mechanism never assumes a fixed line structure for
config.php, which was the root cause of the corruption described above. Both the defaultconfig.phpand any custom file based onconfig-sample.txt(with its leading comment block) now save safely without breaking PHP syntax.