Skip to content

Commit

Permalink
Merge pull request #3 from nswdpc/ss410
Browse files Browse the repository at this point in the history
SS 4.10.0 updates
  • Loading branch information
tardinha authored Oct 11, 2022
2 parents 2f1434d + cbe22b7 commit ff7385d
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 75 deletions.
23 changes: 12 additions & 11 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/tests export-ignore
/docs export-ignore
/client/src export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs.dist
/phpcs.xml.dist
/phpstan.neon.dist
/phpunit.xml.dist
/.waratah export-ignore
/README.md export-ignore
/tests export-ignore
/docs export-ignore
/client/src export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpunit.xml.dist export-ignore
/.waratah export-ignore
/code-of-conduct.md export-ignore
/CONTRIBUTING.md export-ignore
/README.md export-ignore
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/client/node_modules
/vendor/
/resources/
/assets/
.DS_Store
/.php_cs.cache
/composer.lock
/silverstripe-cache/
/.php_cs.fixer.cache
4 changes: 2 additions & 2 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);

return PhpCsFixer\Config::create()
->setRules([
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR2' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Please use dedicated upload fields for handling file uploads.

Per [composer.json](/composer.json):

+ silverstripe/framework ^4
+ silverstripe/framework ^4.10.0
+ jQuery 3.6.0

The field pulls in required Trumbowyg JS and CSS assets from [cdnjs.com](https://cdnjs.com) along with their respective Sub Resource Integrity (SRI) hashes.
Expand Down
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@
]
},
"require": {
"silverstripe/framework" : "^4",
"silverstripe/framework" : "^4.10.0",
"ezyang/htmlpurifier" : "^4.13"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0",
"friendsofphp/php-cs-fixer": "^2.18",
"codeception/codeception" : "^2.5 | ^3 | ^4",
"silverstripe/sqlite3": "^2",
"symbiote/silverstripe-phpstan": "^4"
"phpunit/phpunit": "^9.5",
"friendsofphp/php-cs-fixer": "^3",
"silverstripe/sqlite3": "^2"
}
}
28 changes: 4 additions & 24 deletions docs/en/001_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ The editor configuration defines a restricted set of tags for saving.

All attributes are removed upon save, except for:

+ the href attribute of the <a> tag
+ the href attribute of the `<a>` tag

Additionally, "javascript:" is removed from the href attribute

## Tag restrictions

By default the following tags are allowed in the editor (see _config/config.yml)

```yaml
```yml
- p
- i
- blockquote
Expand All @@ -37,33 +37,13 @@ By default the following tags are allowed in the editor (see _config/config.yml)
Only the `href` attribute is allowed (for links), with http or https schemes.

If no configuration value `tagsToKeep` is available or it is empty, a default set is used. The fallback condition is to restrict to '<p>' tags only.
If no configuration value `tagsToKeep` is available or it is empty, a default set is used. The fallback condition is to restrict to `<p>` tags only.

The editor is provided a set of `tagsToRemove` for client-side editing (see _config/config.yml). This configuration is not used in saving the value, as value saving is determined by the `tagsToKeep` only.

## Options

If no configuration is provided, the following configuration is set:

```php
$options = [
"semantic" => true, // Generates a better, more semantic oriented HTML
"removeformatPasted" => true, // remove pasted styles from Word and friends
"resetCss" => true, // ref: https://alex-d.github.io/Trumbowyg/documentation/#reset-css
"autogrow" => true, // allow the text edit zone to extend
"buttons" => [
[ "undo", "redo" ],
[ "p","h3", "h4", "h5", "strong", "em" ], // basic formatting
[ "link", "" ], // support adding <a> links
[ "unorderedList", "orderedList" ], // ul and ol
[ "removeformat" ], // clear all formatting to assist with removing cruft
[ "fullscreen" ] // go full screen edit
],
"tagsToKeep" => [
"p" // only keep <p> tags by default
]
];
```
If no configuration is provided, the default configuration defined in [TrumbowygEditorField::getFieldOptions()](../../src/Fields/TrumbowygEditorField.php) is used.

## Basic example

Expand Down
11 changes: 0 additions & 11 deletions phpcs.xml.dist

This file was deleted.

6 changes: 0 additions & 6 deletions phpstan.neon.dist

This file was deleted.

9 changes: 1 addition & 8 deletions src/Models/ContentSanitiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ class ContentSanitiser {
* @return string
*/
public static function getAllowedHTMLTags() : string {
$allowedHTMLTags = "";
if(!empty($options['tagsToKeep']) && is_array($options['tagsToKeep'])) {
// mogrify into something for strip_tags
$allowedHTMLTags = "<" . implode("><", $options['tagsToKeep']) . ">";
}
if($allowedHTMLTags == "") {
$allowedHTMLTags = Config::inst()->get(self::class, 'default_allowed_html_tags');
}
$allowedHTMLTags = Config::inst()->get(self::class, 'default_allowed_html_tags');
if($allowedHTMLTags == "") {
$allowedHTMLTags = "<p>";// disallow all
}
Expand Down
25 changes: 25 additions & 0 deletions tests/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,29 @@ public function testGenerateConfig() {
$this->assertEquals( $expected, $config, "Configuration is not as expected" );
}

/**
* test that only <p> tags are returned
*/
public function testEmptyConfig() {
$tags = "";
Config::inst()->update(
ContentSanitiser::class,
'default_allowed_html_tags',
$tags
);
$expectedGeneratedTags = ['p'];
$generatedTags = ContentSanitiser::getAllowedHTMLTagsAsArray();
$this->assertEquals( $expectedGeneratedTags, $generatedTags, "Generated tags should match expected");

$config = ContentSanitiser::generateConfig();
$expected = [
'Core.Encoding' => 'UTF-8',
'HTML.AllowedElements' => $expectedGeneratedTags,
'HTML.AllowedAttributes' => ['href'],
'URI.AllowedSchemes' => ['http','https', 'mailto', 'callto'],
'Attr.ID.HTML5' => true
];
$this->assertEquals( $expected, $config, "Configuration is not as expected" );
}

}

0 comments on commit ff7385d

Please sign in to comment.