-
-
Notifications
You must be signed in to change notification settings - Fork 61
refactor(modulesadmin): replace $myts->htmlSpecialChars() with native… #1689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
043d7b7
075b5e6
b17dd2e
63e8ba9
a07d75d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -831,10 +831,6 @@ function xoops_module_update($dirname) | |
| global $xoopsUser, $xoopsConfig, $xoopsTpl; | ||
| $dirname = trim((string) $dirname); | ||
| $xoopsDB =& $GLOBALS['xoopsDB']; | ||
|
|
||
| $myts = \MyTextSanitizer::getInstance(); | ||
|
|
||
| $dirname = $myts->htmlSpecialChars(trim($dirname)); | ||
| /** @var XoopsModuleHandler $module_handler */ | ||
| $module_handler = xoops_getHandler('module'); | ||
| $module = $module_handler->getByDirname($dirname); | ||
|
|
@@ -876,7 +872,7 @@ function xoops_module_update($dirname) | |
| } | ||
| $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version'); | ||
| if ($module->getInfo('author') !== false && trim($module->getInfo('author')) != '') { | ||
| $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . $myts->htmlSpecialChars(trim($module->getInfo('author'))); | ||
| $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')), ENT_QUOTES | ENT_HTML5, 'UTF-8'); | ||
|
||
| } | ||
| $msgs[] = '</div><div class="logger">'; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,6 @@ parameters: | |||||
| - htdocs/xoops_lib/vendor/ | ||||||
| scanFiles: | ||||||
| - htdocs/xoops_lib/vendor/kint-php/kint/src/Kint.php | ||||||
| bootstrapFiles: | ||||||
| - constants.php | ||||||
| stubFiles: | ||||||
| - phpstan-constants.stub.php | ||||||
|
coderabbitai[bot] marked this conversation as resolved.
Comment on lines
+22
to
+23
|
||||||
| stubFiles: | |
| - phpstan-constants.stub.php |
Copilot
AI
Apr 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description’s explicit file list does not mention phpstan.neon, but this PR modifies it. Either update the PR description to include this change or move the PHPStan config update into a separate PR to keep the scope clear.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,21 +215,29 @@ public function testSanitizesPostDataUsingFilterInput(): void | |
| } | ||
|
|
||
| /** | ||
| * Verify that MyTextSanitizer is used for HTML output sanitization. | ||
| * Verify that htmlspecialchars is used for display output, but NOT for | ||
| * dirnames that feed into DB lookups and filesystem operations. | ||
| */ | ||
| public function testUsesTextSanitizerForOutput(): void | ||
| public function testUsesHtmlspecialcharsForDisplayOnly(): void | ||
| { | ||
| // Display names (list operation) are escaped for HTML output | ||
| $this->assertStringContainsString( | ||
| '$myts = \MyTextSanitizer::getInstance();', | ||
| 'htmlspecialchars(', | ||
| $this->sourceCode, | ||
| 'Should initialize MyTextSanitizer' | ||
| 'Should use htmlspecialchars for display output' | ||
| ); | ||
|
|
||
| // Should use htmlSpecialChars for output | ||
| $this->assertStringContainsString( | ||
| // MyTextSanitizer should no longer be used — dirnames and display | ||
| // names now use native htmlspecialchars where appropriate | ||
| $this->assertStringNotContainsString( | ||
| '$myts->htmlSpecialChars', | ||
| $this->sourceCode, | ||
| 'Should use htmlSpecialChars for output sanitization' | ||
| 'Should not use MyTextSanitizer htmlSpecialChars' | ||
| ); | ||
| $this->assertStringNotContainsString( | ||
| 'MyTextSanitizer::getInstance()', | ||
| $this->sourceCode, | ||
| 'Should not instantiate MyTextSanitizer' | ||
| ); | ||
|
Comment on lines
225
to
241
|
||
| } | ||
|
Comment on lines
217
to
242
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$moduleis used as a module dirname forloadInfoAsVar()/getByDirname()and is also passed toxoops_confirm()(which already escapes hidden values). HTML-escaping it here can change the identifier (e.g.,&->&) and can also lead to double-escaped hidden fields. Prefer validating/normalizing the dirname (e.g.,basename()+ allowed-char regex or membership inXoopsLists::getModulesList()like the *_ok branches) and only escape when interpolating into HTML output.