Skip to content
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

Sanitizer features #467

Merged
merged 18 commits into from
Oct 23, 2018
Merged

Sanitizer features #467

merged 18 commits into from
Oct 23, 2018

Conversation

khaydarov
Copy link
Member

No description provided.

* When Tool's "inlineToolbar" value is True, get all sanitizer rules from all tools,
* otherwise get only enabled
*/
private getSanitizerConfig(name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше вынести в санитайзер

* Sets sanitizer configuration. Uses default config if user didn't pass the restriction
*/
public get defaultConfig() {
return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

От дефолтом теперь же можно избавиться

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а как же санитайз ядра при вставке? в плагинах sanitize - опциональное поле. Оно применяется при сохранении, но не при вставке

Copy link
Member

@gohabereg gohabereg Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Он будет сформирован инлайн тулами

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а, да, ок

*/
private getSanitizerConfig(name) {
const toolsConfig = this.Editor.Tools.getToolSettings(name),
enableInlineTools = toolsConfig.inlineToolbar || [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

к настройкам плагинов надо обращаться через Tools.apiSettings.IS_ENABLED_INLINE_TOOLBAR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enabledInlineTools

docs/api.md Outdated
@@ -34,11 +34,16 @@ Methods that working with Blocks

```insertNewBlock()``` - insert new Block after working place

```getSanitizerConfig()``` - method return allowed inline-tool's sanitizer rules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот метод работает только с инлайн тулами. То есть это нельзя назвать sanitizerConfig, тк там нету конфета самого плагина. Он должен либо отдавать полный конфиг (sanitize плагина + sanitize инлайн тулов), либо называться getInlineToolsSanitizerConfig. Первый вариант лучше

* getting only enabled
*/
enableInlineTools.map( (inlineToolName) => {
config = Object.assign(config, this.Editor.InlineToolbar.tools.get(inlineToolName).sanitize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

надо учесть, что sanitize — это опциональное поле, то есть его может не быть. И в инлайн тулах тоже.

/**
* getting all tools sanitizer rule
*/
this.Editor.InlineToolbar.tools.forEach( (inlineTool) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему тут inlineTool, а ниже inlineToolName ? лучше везде inlineToolName

cleanData;

blocks.forEach((block) => {
baseConfig = this.getSanitizerConfig(block.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше, чтобы метод getSanitizerConfig возвращал уже смердженный конфиг санитайза (а не только инлайн-тулы). То есть, вся логика по формированию конфига будет в одном месте. И код deepSanitize упростится за счет того, что не будет baseConfig

*
* @return {String} clean HTML
*/
public clean(taintString: string, customConfig: ISanitizerConfig) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

надо указать возвращаемые значения функций

* @param {Object} rules - object with sanitizer rules
* @param {Object} baseConfig - object with sanitizer rules from inline-tools
*/
public deepSanitize(blockData, rules, baseConfig) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно указать тип параметров и возвращаемого значения

/**
* Method recursively reduces Block's data and cleans with passed rules
*
* @param {Object|string} blockData - taint string or object/array that contains taint string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у нас есть интерфейс IBlockData или вроде того

* Method recursively reduces Block's data and cleans with passed rules
*
* @param {Object|string} blockData - taint string or object/array that contains taint string
* @param {Object} rules - object with sanitizer rules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

такой интерфейс тоже есть вроде

for (const data in blockData) {
if (Array.isArray(blockData[data]) || typeof blockData[data] === 'object') {
/**
* Case 1 & Case 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пишешь, что два кейса, но в коде три кейса: if, elseif, else. Не понятно что тогда else.

package.json Show resolved Hide resolved
super({config});

/** Custom configuration */
this.sanitizerConfig = config.settings ? config.settings.sanitizer : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

актуализировать

src/components/modules/sanitizer.ts Show resolved Hide resolved
return blocksData.map((block) => {
toolClass = this.Editor.Tools.toolsAvailable[block.tool];

const output = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно убрать

/**
* Enable sanitizing if Tool provides config
*/
if (toolClass.sanitize && !_.isEmpty(toolClass.sanitize)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

развернуть иф

* 2) If rule is false, which means clean all
* 3) Do nothing
*/
if (rules[data]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вынести иф

* 3. When Data is base type (string, int, bool, ...). Check if rule is passed
*/
for (const data in blockData) {
if (Array.isArray(blockData[data])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вынести иф

* Merge with inline tool config
*
* @param {string} toolName
* @param {ISanitizerConfig} blockRules
Copy link
Member

@neSpecc neSpecc Oct 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toolConfig


const toolConfig = {};
for (const blockRule in blockRules) {
if (blockRules[blockRule]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blockRules[blockRule] !== false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • учесть true

Copy link
Member

@gohabereg gohabereg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Потести еще paste, чтобы все ок было с санитайзингом

package.json Show resolved Hide resolved
@@ -152,7 +152,7 @@ export default class Paste extends Module {
return result;
}, {});

const customConfig = Object.assign({}, toolsTags, Sanitizer.defaultConfig.tags);
const customConfig = Object.assign({}, toolsTags, Sanitizer.defaultConfig);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

обсудить с @gohabereg

*/
public deepSanitize(blockData, rules, depth = 0) {

console.log('start: depth', depth);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log

* @param {ISanitizerConfig} rules - object with sanitizer rules
* @param {number} depth
*/
public deepSanitize(blockData, rules, depth = 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove deph

*
* 1) Array - we need to save as array, thats why we do Array.map and call itself recursively
* 2) Object - we make new object with clean data and call itself
* 3) Basic type - we clean data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boolean/string/number

* 2) Object - we make new object with clean data and call itself
* 3) Basic type - we clean data
*/
for (const data in blockData) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data -> fieldName

* - if passed config is not valid, call itself with parent's config
*/
if (this.isConfigValid(rules[data])) {
cleanData[data] = currentIterationItem.map( (arrayData) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrayData -> arrayItem

@khaydarov khaydarov merged commit 3f8c7fb into master Oct 23, 2018
@khaydarov khaydarov deleted the sanitizer-new-features branch October 23, 2018 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants