Skip to content

Commit

Permalink
Merge pull request #13 from Esri/update-dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
ssylvia authored Sep 24, 2018
2 parents 89be985 + af6ee26 commit 45f5882
Show file tree
Hide file tree
Showing 5 changed files with 769 additions and 2,166 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ yarn add @esri/arcgis-html-sanitizer
ES Modules

```js
import { Sanitizer } from '@esri/arcgis-html-sanitizer';
import { Sanitizer } from "@esri/arcgis-html-sanitizer";
```

CommonJS

```js
const Sanitizer = require('@esri/arcgis-html-sanitizer').Sanitizer;
const Sanitizer = require("@esri/arcgis-html-sanitizer").Sanitizer;
```

AMD (Use UMD version in ./dist/umd folder)
Expand All @@ -89,7 +89,7 @@ Load as script tag
<script src="path/to/arcgis-html-sanitizer.min.js"></script>

<!-- CDN (Adjust the version as needed) -->
<script src="https://cdn.jsdelivr.net/npm/@esri/arcgis-html-sanitizer@0.5.0/dist/umd/arcgis-html-sanitizer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@esri/arcgis-html-sanitizer@0.6.0/dist/umd/arcgis-html-sanitizer.min.js"></script>
```

#### Basic Usage
Expand Down
40 changes: 23 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "@esri/arcgis-html-sanitizer",
"version": "0.5.0",
"description":
"A simple utility to sanitize a string according to ArcGIS supported HTML specification.",
"version": "0.6.0",
"description": "A simple utility to sanitize a string according to ArcGIS supported HTML specification.",
"main": "dist/node/index.js",
"repository": "https://github.com/Esri/arcgis-html-sanitizer.git",
"bugs": {
Expand All @@ -14,7 +13,7 @@
"scripts": {
"build": "yarn run build:node && yarn run build:esm && yarn run build:umd",
"build:esm": "tsc --module ESNext --outDir ./dist/esm --declaration",
"build:node": "tsc --module commonjs --outDir ./dist/node",
"build:node": "tsc --module commonjs --outDir ./dist/node --declaration",
"build:umd": "webpack --mode development && webpack --mode production",
"lint": "tslint --project tsconfig.json",
"lint:fix": "tslint --project tsconfig.json --fix",
Expand All @@ -39,24 +38,31 @@
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test))\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
},
"dependencies": {
"lodash.isplainobject": "^4.0.6",
"xss": "^0.3.8"
"xss": "^1.0.3"
},
"devDependencies": {
"@types/jest": "^22.2.0",
"@types/lodash.isplainobject": "^4.0.3",
"jest": "^22.4.2",
"ts-jest": "^22.4.1",
"ts-loader": "^4.0.1",
"tslint": "^5.9.1",
"tslint-config-prettier": "^1.9.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.7.2",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.10"
"@types/jest": "^23.3.2",
"@types/lodash.isplainobject": "^4.0.4",
"jest": "^23.6.0",
"ts-jest": "^23.10.1",
"ts-loader": "^5.2.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.0.3",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.1"
},
"publishConfig": {
"access": "public"
Expand Down
40 changes: 21 additions & 19 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Sanitizer } from './index';
import { Sanitizer } from "./index";

// This file contains basic tests that validate the the utility methods.
// For XSS attack sanitizer testing see xss.test.ts

describe('Sanitizer', () => {
test('creates the Sanitizer object and extends options appropriately', () => {
describe("Sanitizer", () => {
test("creates the Sanitizer object and extends options appropriately", () => {
// Test with no arguments
const sanitizer1 = new Sanitizer();
const defaultSanitizer1 = new Sanitizer();
Expand All @@ -27,6 +27,7 @@ describe('Sanitizer', () => {
expect(sanitizer2.xssFilterOptions).toEqual(filterOptions2);

// Passing an empty whitelist
// @ts-ignore
const sanitizer3 = new Sanitizer({ whiteList: null }, true);
const defaultSanitizer3 = new Sanitizer();
const defaultOptions3 = Object.create(
Expand All @@ -40,7 +41,7 @@ describe('Sanitizer', () => {
expect(sanitizer4.xssFilterOptions).toEqual({ whiteList: { a: [] } });
});

test('sanitizes a value', () => {
test("sanitizes a value", () => {
const sanitizer = new Sanitizer();

// Numbers
Expand All @@ -54,7 +55,7 @@ describe('Sanitizer', () => {
expect(sanitizer.sanitize(false)).toBe(false);

// Strings
const basicString = 'Hello World';
const basicString = "Hello World";
const validHtml = 'Hello <a href="https://example.org">Link</a>';
const invalidHtml =
'Evil <img src="https://exmaple.org/myImg.jpg" onerror="alert(1)" />';
Expand Down Expand Up @@ -131,19 +132,20 @@ describe('Sanitizer', () => {
expect(sanitizer.sanitize(Intl.NumberFormat)).toBe(null);

// Others
// @ts-ignore
expect(sanitizer.sanitize(arguments)).toBe(null);
expect(sanitizer.sanitize(() => 'test')).toBe(null);
expect(sanitizer.sanitize(new Error('test'))).toBe(null);
expect(sanitizer.sanitize(() => "test")).toBe(null);
expect(sanitizer.sanitize(new Error("test"))).toBe(null);
});

test('deeply sanitizes an object', () => {
test("deeply sanitizes an object", () => {
const sanitizer = new Sanitizer();

// If object is clean, it return the exact same object;
const cleanObj1 = {
a: null,
b: true,
c: 'clean string'
c: "clean string"
};
const result1 = sanitizer.sanitize(cleanObj1);
expect(result1).toBe(cleanObj1);
Expand All @@ -152,34 +154,34 @@ describe('Sanitizer', () => {
const result2 = sanitizer.sanitize({
a: 1,
b: true,
c: 'clean string',
c: "clean string",
d: 'Evil <img src="https://exmaple.org/myImg.jpg" onerror="alert(1)" />',
e: [
1,
true,
'Evil <img src="https://exmaple.org/myImg.jpg" onerror="alert(1)" />',
['inner', 'array']
["inner", "array"]
],
f: new Date()
});
const expected2 = {
a: 1,
b: true,
c: 'clean string',
c: "clean string",
d: 'Evil <img src="https://exmaple.org/myImg.jpg" />',
e: [
1,
true,
'Evil <img src="https://exmaple.org/myImg.jpg" />',
['inner', 'array']
["inner", "array"]
],
f: null
};
expect(result2).toEqual(expected2);
});

test('checks if string is valid html', () => {
const basicString = 'Hello World';
test("checks if string is valid html", () => {
const basicString = "Hello World";
const validHtml = 'Hello <a href="https://example.org">Link</a>';
const invalidHtml =
'Evil <img src="https://exmaple.org/myImg.jpg" onerror="alert(1)" />';
Expand All @@ -191,9 +193,9 @@ describe('Sanitizer', () => {
expect(sanitizer.validate(invalidHtml).isValid).toBe(false);
});

test('extends an object of array by concatenating arrays', () => {
test("extends an object of array by concatenating arrays", () => {
// tslint:disable-next-line:no-string-literal
const _extendObjectOfArrays = new Sanitizer()['_extendObjectOfArrays'];
const _extendObjectOfArrays = new Sanitizer()["_extendObjectOfArrays"];

const result = _extendObjectOfArrays([
{ a: [1, 2] },
Expand All @@ -204,9 +206,9 @@ describe('Sanitizer', () => {
expect(result).toEqual({ a: [1, 2, 3, 4], b: [1, 2, 3, 4] });
});

test('returns null of iteration fails', () => {
test("returns null of iteration fails", () => {
// tslint:disable-next-line:no-string-literal
const _iterateOverObject = new Sanitizer()['_iterateOverObject'];
const _iterateOverObject = new Sanitizer()["_iterateOverObject"];

// Will fail because "this" is not defined
expect(_iterateOverObject({ a: 1 })).toBe(null);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"lib": ["es6"],
"target": "es5",
"module": "ESNext",
"moduleResolution": "node",
Expand Down
Loading

0 comments on commit 45f5882

Please sign in to comment.