-
-
Notifications
You must be signed in to change notification settings - Fork 527
[3.x] Form handler refactor to allow more flexible and accurate status reporting in the manager UI #17023
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
Open
smg6511
wants to merge
14
commits into
modxcms:3.x
Choose a base branch
from
smg6511:3.x-form-handler-refactor
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,094
−51
Open
[3.x] Form handler refactor to allow more flexible and accurate status reporting in the manager UI #17023
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
190295e
Initial WIP
smg6511 e9b81a5
WIP round 2
smg6511 b97ee9a
Update CheckForUpdates.php
smg6511 4d74b11
Minor clean up
smg6511 3fc47c8
Update CheckForUpdates.php
smg6511 0b1bc12
Update modx.js
smg6511 9eea3a8
Rename util classes
smg6511 a9a9caa
Pre-submission tweaks and unit test
smg6511 1b3b95b
Update phpunit.xml
smg6511 4363121
Example usage in package update
smg6511 76a8e0c
Final processor and message box config tweaks
smg6511 3afdf07
WIP 3
smg6511 22b8dad
Final pre-submission tweaks
smg6511 6860105
Unit test additions
smg6511 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,211 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the MODX Revolution package. | ||
| * | ||
| * Copyright (c) MODX, LLC | ||
| * | ||
| * For complete copyright and license information, see the COPYRIGHT and LICENSE | ||
| * files found in the top-level directory of this distribution. | ||
| * | ||
| * @package modx-test | ||
| */ | ||
|
|
||
| /** @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps */ | ||
|
|
||
| namespace MODX\Revolution\Tests\Utilities\Sanitizers; | ||
|
|
||
| use MODX\Revolution\MODxTestCase; | ||
| use MODX\Revolution\Utilities\Sanitizers\modStringSanitizer; | ||
|
|
||
| class modStringSanitizerTest extends MODxTestCase | ||
| { | ||
| /** @var modStringSanitizer $sanitizers */ | ||
| public $sanitizers; | ||
|
|
||
| /** | ||
| * Setup fixtures before each test. | ||
| * | ||
| * @before | ||
| */ | ||
| public function setUpFixtures() | ||
| { | ||
| parent::setUpFixtures(); | ||
| $this->sanitizers = $this->modx->services->get(modStringSanitizer::class); | ||
| } | ||
|
|
||
| /** | ||
| * @param string $expected | ||
| * @param string $htmlSource The html string to clean | ||
| * @param ?string|array $allowedTags An array or comma-separated list of tag names to allow | ||
| * @param ?string|array $allowedAttr An array or comma-separated list of tag attribute names to allow | ||
| * @param bool $allowScripts Whether to allow javascript in html source passed to this method | ||
| * @param bool $allowComments Whether to allow comments in the final output | ||
| * @dataProvider providerStripHTML | ||
| */ | ||
| public function testStripHTML( | ||
| $expected, | ||
| string $htmlSource, | ||
| string|array|null $allowedTags = '', | ||
| string|array|null $allowedAttr = '', | ||
| bool $allowScripts = false, | ||
| bool $allowComments = false | ||
| ) { | ||
|
|
||
| $allowedTags = $allowedTags ?? ''; | ||
| $allowedAttr = $allowedAttr ?? ''; | ||
|
|
||
| $result = $this->sanitizers->stripHTML($htmlSource, $allowedTags, $allowedAttr, $allowScripts, $allowComments); | ||
| $this->assertEquals($expected, $result); | ||
| } | ||
|
|
||
| public function providerStripHTML(): array | ||
| { | ||
| $nullParams = [null, null]; | ||
| // String list configs (including odd spacing) | ||
| $parmSet1 = ['a, strong , em', 'href, title,id']; | ||
| // Array list configs (including odd spacing) | ||
| $parmSet2 = [['p', 'a', ' strong', 'em'], ['href ', 'class', 'style', 'onclick', 'title']]; | ||
| // Custom/non-existing | ||
| $parmSet3 = ['p, notatag', 'notanattr']; | ||
| // Data attr and allowing scripts | ||
| $parmSet4 = ['div,img, script', 'data, src', true]; | ||
|
|
||
| // Have to hack this to keep parser from interpreting as actual opening short tag in the tests below | ||
| $shortOpenTag = <<<TAG | ||
| <? | ||
| TAG; | ||
|
|
||
| return [ | ||
| // Full strip, nothing passed in for allowed params | ||
| 'Should remove all tags and attrs' => [ | ||
| 'My great string', | ||
| '<p class="gone">My <em>great</em> string</p>' | ||
| ], | ||
| 'Should remove all tags and attrs (when null is passed to allowed params)' => [ | ||
| 'My great string', | ||
| '<p class="gone">My <em>great</em> string</p>', | ||
| ...$nullParams | ||
| ], | ||
| 'Should remove script tag and its contents' => [ | ||
| 'This would , but we fixed it.', | ||
| 'This would <script>alert("be bad");</script>, but we fixed it.' | ||
| ], | ||
| 'Should remove broken script tag and remaining contents (no closing)' => [ | ||
| 'This would ', | ||
| 'This would <script>alert("be bad");, but we fixed it.' | ||
| ], | ||
| 'Should remove broken script tag (no opening)' => [ | ||
| 'This would alert("be bad");', | ||
| 'This would alert("be bad");</script>' | ||
| ], | ||
| 'Should remove php (long tag)' => [ | ||
| '', | ||
| '<?php echo "Also not great!"; ?>' | ||
| ], | ||
| 'Should remove php (long incomplete tag)' => [ | ||
| '', | ||
| '<?php echo "Again, not great!";' | ||
| ], | ||
| 'Should remove php (short tag)' => [ | ||
| '', | ||
| trim($shortOpenTag) . ' echo "Still not great!"; ?>' | ||
| ], | ||
| 'Should remove php (short incomplete tag)' => [ | ||
| '', | ||
| trim($shortOpenTag) . ' echo "You know ... not great!";' | ||
| ], | ||
| /* | ||
| paramSet1 rules, allowed: | ||
| tags -- a, strong, em | ||
| attr -- href, title, id | ||
| */ | ||
| 'Should auto complete broken em (incorrect closing tags)' => [ | ||
| 'A <em>jazzy<em> caption</em></em>', | ||
| 'A <em>jazzy<em> caption', | ||
| ...$parmSet1 | ||
| ], | ||
| 'Should handle removals in nested structures' => [ | ||
| 'A <em>jazzy</em> caption <a id="myId">more</a>', | ||
| 'A <b><em><span>jazzy</span></em></b> caption <span><a id="myId" style="color: red;"><b>more</b></a></span>', | ||
| ...$parmSet1 | ||
| ], | ||
| /* | ||
| paramSet2 rules, allowed, given in array instead of string: | ||
| tags -- ['p', 'a', 'strong', 'em'] | ||
| attr -- ['href', 'class', 'style', 'onclick', 'title'] {1} | ||
|
|
||
| {1} note that event handlers should always be removed, even when scripts | ||
| are allowed as it is bad practice mixing javascript directly in html | ||
| */ | ||
| 'Should remove non-standard tag and others not in list' => [ | ||
| '<p>A jazzy caption</p>', | ||
| '<div><p>A <notatag>jazzy</notatag> caption</p></div>', | ||
| ...$parmSet2 | ||
| ], | ||
| 'Should remove event handlers' => [ | ||
| '<p class="myClass">This element does <strong>all</strong> these things</p>', | ||
| '<p class="myClass" data-someprop="hello">This <b>element</b> does <strong onclick="javascript:alert(hello);">all</strong> these things</p>', | ||
| ...$parmSet2 | ||
| ], | ||
| 'Should replace javascript in all attrs' => [ | ||
| '<p class="myClass">This element does <strong title="#js-not-allowed#">all</strong> these things</p>', | ||
| '<p class="myClass" data-someprop="hello">This <b>element</b> does <strong title="javascript:alert(hello);">all</strong> these things</p>', | ||
| ...$parmSet2 | ||
| ], | ||
| /* | ||
| paramSet3 rules, allowed: | ||
| tags -- p, notatag | ||
| attr -- notanattr | ||
| */ | ||
| 'Should retain non-standard and other allowed tags' => [ | ||
| '<p>A <notatag>jazzy</notatag> caption</p>', | ||
| '<div><p>A <notatag>jazzy</notatag> caption</p></div>', | ||
| ...$parmSet3 | ||
| ], | ||
| 'Should retain non-standard and other allowed attributes' => [ | ||
| '<p notanattr="technically ok, but not advisable">A <notatag>jazzy</notatag> caption</p>', | ||
| '<div><p notanattr="technically ok, but not advisable">A <notatag>jazzy</notatag> caption</p></div>', | ||
| ...$parmSet3 | ||
| ], | ||
| /* | ||
| paramSet4 rules, allowed: | ||
| tags -- div, img, script | ||
| attr -- data, src | ||
| */ | ||
| 'Should retain data attributes' => [ | ||
| '<div data-someprop="hello" data-otherprop="world">A jazzy caption</div>', | ||
| '<div data-someprop="hello" data-otherprop="world"><p>A <notatag>jazzy</notatag> caption</p></div>', | ||
| ...$parmSet4 | ||
| ], | ||
| 'Should retain script tag and contents' => [ | ||
| '<div>As long as you are sure, </div><script>alert("you can do this");</script>', | ||
| '<div>As long as you are sure, </div><script>alert("you can do this");</script>', | ||
| ...$parmSet4 | ||
| ], | ||
| 'Should handle retention and removals in multiline html' => [ | ||
| <<<EXP | ||
| <div> | ||
| These tags will disappear | ||
| <img src="/some/path/to.png"> | ||
| </div> | ||
| <script> | ||
| let x = 1; | ||
| console.log('X is ', x); | ||
| </script> | ||
| EXP, | ||
| <<<SRC | ||
| <div> | ||
| <p>These tags will <span>disappear</span></p> | ||
| <img src="/some/path/to.png" alt="should have this but not in list"> | ||
| </div> | ||
| <script> | ||
| let x = 1; | ||
| console.log('X is ', x); | ||
| </script> | ||
| SRC, | ||
| ...$parmSet4 | ||
| ] | ||
| ]; | ||
| } | ||
| } | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.