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

fix(binding): remove unnecessary sanitizer in BindingService #947

Merged
merged 3 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/binding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@
"> 1%",
"not dead"
],
"dependencies": {
"dompurify": "^3.0.1"
},
"devDependencies": {
"@types/dompurify": "^3.0.1",
"cross-env": "^7.0.3",
Expand Down
2 changes: 0 additions & 2 deletions packages/binding/src/binding.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export class BindingHelper {
return this._observers;
}

constructor() { }

dispose() {
let observer = this._observers.pop();
while (observer) {
Expand Down
19 changes: 6 additions & 13 deletions packages/binding/src/binding.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* eslint-disable no-bitwise */
import * as DOMPurify_ from 'dompurify';
const DOMPurify = ((DOMPurify_ as any)?.['default'] ?? DOMPurify_); // patch for rollup

import { Binding, BoundedEventWithListener, ElementBinding, ElementBindingWithListener } from './interfaces';

/**
Expand All @@ -22,9 +18,9 @@ export class BindingService {
this._property = binding.property || '';
this._elementBindings = [];
if (binding.property && binding.variable && (binding.variable.hasOwnProperty(binding.property) || binding.property in binding.variable)) {
this._value = typeof binding.variable[binding.property] === 'string' ? this.sanitizeText(binding.variable[binding.property]) : binding.variable[binding.property];
this._value = binding.variable[binding.property];
} else {
this._value = typeof binding.variable === 'string' ? this.sanitizeText(binding.variable) : binding.variable;
this._value = binding.variable;
}

if (typeof binding.variable === 'object') {
Expand Down Expand Up @@ -58,11 +54,11 @@ export class BindingService {
}

valueSetter<T extends Element = Element>(val: any) {
this._value = typeof val === 'string' ? this.sanitizeText(val) : val;
this._value = val;
if (Array.isArray(this._elementBindings)) {
for (const binding of this._elementBindings) {
if (binding?.element && binding?.attribute) {
(binding.element as T)[binding.attribute as keyof T] = typeof val === 'string' ? this.sanitizeText(val) : val;
(binding.element as T)[binding.attribute as keyof T] = val;
}
}
}
Expand Down Expand Up @@ -139,13 +135,14 @@ export class BindingService {
this._boundedEventWithListeners.push({ element, eventName, listener, uid: this.generateUuidV4() });
}
this._elementBindings.push(binding);
element[attribute as keyof T] = typeof this._value === 'string' ? this.sanitizeText(this._value) : this._value;
element[attribute as keyof T] = this._value;
}
}

/** Generate a UUID version 4 RFC compliant */
protected generateUuidV4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
/* eslint-disable no-bitwise */
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
Expand All @@ -155,8 +152,4 @@ export class BindingService {
protected hasData(value: any): boolean {
return value !== undefined && value !== null && value !== '';
}

protected sanitizeText(dirtyText: string): string {
return (DOMPurify?.sanitize) ? DOMPurify.sanitize(dirtyText, {}) : dirtyText;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class SlickPaginationComponent {
constructor(protected readonly paginationService: PaginationService, protected readonly pubSubService: PubSubService, protected readonly sharedService: SharedService, protected readonly translaterService?: TranslaterService) {
this._bindingHelper = new BindingHelper();
this._bindingHelper.querySelectorPrefix = `.${this.gridUid} `;

this.currentPagination = this.paginationService.getFullPagination();
this._enableTranslate = this.gridOptions?.enableTranslate ?? false;

Expand Down Expand Up @@ -202,7 +201,7 @@ export class SlickPaginationComponent {
this._bindingHelper.bindEventHandler('.icon-seek-end', 'click', this.changeToLastPage.bind(this) as EventListener);
this._bindingHelper.bindEventHandler('.icon-seek-next', 'click', this.changeToNextPage.bind(this) as EventListener);
this._bindingHelper.bindEventHandler('.icon-seek-prev', 'click', this.changeToPreviousPage.bind(this) as EventListener);
this._bindingHelper.bindEventHandler('select.items-per-page', 'change', (event: & { target: any }) => this.itemsPerPage = +(event?.target?.value ?? 0));
this._bindingHelper.bindEventHandler('select.items-per-page', 'change', (event: & { target: any; }) => this.itemsPerPage = +(event?.target?.value ?? 0));
}

changeToFirstPage(event: MouseEvent) {
Expand Down Expand Up @@ -267,7 +266,7 @@ export class SlickPaginationComponent {
return paginationElm;
}

protected createPageNavigation(navAriaLabel: string, liElements: Array<{ liClass: string, aClass: string, ariaLabel: string }>) {
protected createPageNavigation(navAriaLabel: string, liElements: Array<{ liClass: string, aClass: string, ariaLabel: string; }>) {
const navElm = createDomElement('nav', { ariaLabel: navAriaLabel });
const ulElm = createDomElement('ul', { className: 'pagination' });

Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/vanilla-force-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
"bundle:commonjs": "tsc --project tsconfig.bundle.json --outDir dist/commonjs --module commonjs",
"bundle:esm": "tsc --project tsconfig.bundle.json --outDir dist/esm --module esnext --target es2018",
"bundle:types": "tsc --emitDeclarationOnly --declarationMap --outDir dist/types",
"bundle:web": "esbuild src/index.ts --bundle --minify --format=iife --sourcemap --sources-content=false --target=es2018 --main-fields=module,main --global-name=Slicker --outfile=dist/bundle/slickgrid-vanilla-bundle.js",
"bundle:web:esbuild": "node esbuild.mjs",
"bundle:esbuild": "node esbuild.mjs",
"bundle:vite": "vite build",
"prebundle:zip": "pnpm run delete:zip",
"bundle:zip": "pnpm run zip:dist",
"delete:zip": "rimraf dist-grid-bundle-zip",
"zip:dist": "node compress.mjs --output-filename=slickgrid-vanilla-bundle --output-folder=\"dist-grid-bundle-zip/\"",
"test": "echo testing slickgrid-universal vanilla-force-bundle code"
},
"note": "there are 2 bundler available vite & esbuild, but we really only use Vite only but we keep esbuild for reference",
"license": "MIT",
"author": "Ghislain B.",
"homepage": "https://github.com/ghiscoding/slickgrid-universal",
Expand Down
4 changes: 0 additions & 4 deletions packages/vanilla-force-bundle/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import path from 'node:path';
// import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite';

// const filename = fileURLToPath(import.meta.url);
// const dirname = path.dirname(filename);

export default defineConfig({
build: {
emptyOutDir: false, // we only use Vite for the "bundle" folder, we need to keep CJS/ESM untouched
Expand Down
Loading