rootaccessxvv-bbmarker 0.0.1-security → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rootaccessxvv-bbmarker might be problematic. Click here for more details.
- package/README.md +13 -3
- package/index.js +1 -0
- package/package.json +17 -6
- package/sim/node_modules/.bin/xss +16 -0
- package/sim/node_modules/.bin/xss.cmd +17 -0
- package/sim/node_modules/.bin/xss.ps1 +28 -0
- package/sim/node_modules/.package-lock.json +36 -0
- package/sim/node_modules/commander/CHANGELOG.md +419 -0
- package/sim/node_modules/commander/LICENSE +22 -0
- package/sim/node_modules/commander/Readme.md +428 -0
- package/sim/node_modules/commander/index.js +1224 -0
- package/sim/node_modules/commander/package.json +38 -0
- package/sim/node_modules/commander/typings/index.d.ts +310 -0
- package/sim/node_modules/cssfilter/LICENSE +22 -0
- package/sim/node_modules/cssfilter/README.md +86 -0
- package/sim/node_modules/cssfilter/lib/css.js +110 -0
- package/sim/node_modules/cssfilter/lib/default.js +398 -0
- package/sim/node_modules/cssfilter/lib/index.js +32 -0
- package/sim/node_modules/cssfilter/lib/parser.js +74 -0
- package/sim/node_modules/cssfilter/lib/util.js +35 -0
- package/sim/node_modules/cssfilter/package.json +49 -0
- package/sim/node_modules/xss/CHANGELOG.md +24 -0
- package/sim/node_modules/xss/LICENSE +23 -0
- package/sim/node_modules/xss/README.md +505 -0
- package/sim/node_modules/xss/README.zh.md +491 -0
- package/sim/node_modules/xss/bin/xss +67 -0
- package/sim/node_modules/xss/dist/test.html +15 -0
- package/sim/node_modules/xss/dist/xss.js +1665 -0
- package/sim/node_modules/xss/dist/xss.min.js +1 -0
- package/sim/node_modules/xss/lib/cli.js +45 -0
- package/sim/node_modules/xss/lib/default.js +459 -0
- package/sim/node_modules/xss/lib/index.js +44 -0
- package/sim/node_modules/xss/lib/parser.js +247 -0
- package/sim/node_modules/xss/lib/util.js +34 -0
- package/sim/node_modules/xss/lib/xss.js +211 -0
- package/sim/node_modules/xss/package.json +63 -0
- package/sim/node_modules/xss/typings/xss.d.ts +202 -0
- package/sim/package-lock.json +44 -0
- package/sim/package.json +16 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "commander",
|
|
3
|
+
"version": "2.20.3",
|
|
4
|
+
"description": "the complete solution for node.js command-line programs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"commander",
|
|
7
|
+
"command",
|
|
8
|
+
"option",
|
|
9
|
+
"parser"
|
|
10
|
+
],
|
|
11
|
+
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/tj/commander.js.git"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"lint": "eslint index.js",
|
|
19
|
+
"test": "node test/run.js && npm run test-typings",
|
|
20
|
+
"test-typings": "tsc -p tsconfig.json"
|
|
21
|
+
},
|
|
22
|
+
"main": "index",
|
|
23
|
+
"files": [
|
|
24
|
+
"index.js",
|
|
25
|
+
"typings/index.d.ts"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^12.7.8",
|
|
30
|
+
"eslint": "^6.4.0",
|
|
31
|
+
"should": "^13.2.3",
|
|
32
|
+
"sinon": "^7.5.0",
|
|
33
|
+
"standard": "^14.3.1",
|
|
34
|
+
"ts-node": "^8.4.1",
|
|
35
|
+
"typescript": "^3.6.3"
|
|
36
|
+
},
|
|
37
|
+
"typings": "typings/index.d.ts"
|
|
38
|
+
}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
// Type definitions for commander 2.11
|
|
2
|
+
// Project: https://github.com/visionmedia/commander.js
|
|
3
|
+
// Definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
|
|
4
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
|
|
6
|
+
declare namespace local {
|
|
7
|
+
|
|
8
|
+
class Option {
|
|
9
|
+
flags: string;
|
|
10
|
+
required: boolean;
|
|
11
|
+
optional: boolean;
|
|
12
|
+
bool: boolean;
|
|
13
|
+
short?: string;
|
|
14
|
+
long: string;
|
|
15
|
+
description: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Initialize a new `Option` with the given `flags` and `description`.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} flags
|
|
21
|
+
* @param {string} [description]
|
|
22
|
+
*/
|
|
23
|
+
constructor(flags: string, description?: string);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class Command extends NodeJS.EventEmitter {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
|
|
29
|
+
args: string[];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Initialize a new `Command`.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} [name]
|
|
35
|
+
*/
|
|
36
|
+
constructor(name?: string);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Set the program version to `str`.
|
|
40
|
+
*
|
|
41
|
+
* This method auto-registers the "-V, --version" flag
|
|
42
|
+
* which will print the version number when passed.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} str
|
|
45
|
+
* @param {string} [flags]
|
|
46
|
+
* @returns {Command} for chaining
|
|
47
|
+
*/
|
|
48
|
+
version(str: string, flags?: string): Command;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Add command `name`.
|
|
52
|
+
*
|
|
53
|
+
* The `.action()` callback is invoked when the
|
|
54
|
+
* command `name` is specified via __ARGV__,
|
|
55
|
+
* and the remaining arguments are applied to the
|
|
56
|
+
* function for access.
|
|
57
|
+
*
|
|
58
|
+
* When the `name` is "*" an un-matched command
|
|
59
|
+
* will be passed as the first arg, followed by
|
|
60
|
+
* the rest of __ARGV__ remaining.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* program
|
|
64
|
+
* .version('0.0.1')
|
|
65
|
+
* .option('-C, --chdir <path>', 'change the working directory')
|
|
66
|
+
* .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
|
|
67
|
+
* .option('-T, --no-tests', 'ignore test hook')
|
|
68
|
+
*
|
|
69
|
+
* program
|
|
70
|
+
* .command('setup')
|
|
71
|
+
* .description('run remote setup commands')
|
|
72
|
+
* .action(function() {
|
|
73
|
+
* console.log('setup');
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* program
|
|
77
|
+
* .command('exec <cmd>')
|
|
78
|
+
* .description('run the given remote command')
|
|
79
|
+
* .action(function(cmd) {
|
|
80
|
+
* console.log('exec "%s"', cmd);
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* program
|
|
84
|
+
* .command('teardown <dir> [otherDirs...]')
|
|
85
|
+
* .description('run teardown commands')
|
|
86
|
+
* .action(function(dir, otherDirs) {
|
|
87
|
+
* console.log('dir "%s"', dir);
|
|
88
|
+
* if (otherDirs) {
|
|
89
|
+
* otherDirs.forEach(function (oDir) {
|
|
90
|
+
* console.log('dir "%s"', oDir);
|
|
91
|
+
* });
|
|
92
|
+
* }
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* program
|
|
96
|
+
* .command('*')
|
|
97
|
+
* .description('deploy the given env')
|
|
98
|
+
* .action(function(env) {
|
|
99
|
+
* console.log('deploying "%s"', env);
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* program.parse(process.argv);
|
|
103
|
+
*
|
|
104
|
+
* @param {string} name
|
|
105
|
+
* @param {string} [desc] for git-style sub-commands
|
|
106
|
+
* @param {CommandOptions} [opts] command options
|
|
107
|
+
* @returns {Command} the new command
|
|
108
|
+
*/
|
|
109
|
+
command(name: string, desc?: string, opts?: commander.CommandOptions): Command;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Define argument syntax for the top-level command.
|
|
113
|
+
*
|
|
114
|
+
* @param {string} desc
|
|
115
|
+
* @returns {Command} for chaining
|
|
116
|
+
*/
|
|
117
|
+
arguments(desc: string): Command;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Parse expected `args`.
|
|
121
|
+
*
|
|
122
|
+
* For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
|
|
123
|
+
*
|
|
124
|
+
* @param {string[]} args
|
|
125
|
+
* @returns {Command} for chaining
|
|
126
|
+
*/
|
|
127
|
+
parseExpectedArgs(args: string[]): Command;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Register callback `fn` for the command.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* program
|
|
134
|
+
* .command('help')
|
|
135
|
+
* .description('display verbose help')
|
|
136
|
+
* .action(function() {
|
|
137
|
+
* // output help here
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* @param {(...args: any[]) => void} fn
|
|
141
|
+
* @returns {Command} for chaining
|
|
142
|
+
*/
|
|
143
|
+
action(fn: (...args: any[]) => void): Command;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Define option with `flags`, `description` and optional
|
|
147
|
+
* coercion `fn`.
|
|
148
|
+
*
|
|
149
|
+
* The `flags` string should contain both the short and long flags,
|
|
150
|
+
* separated by comma, a pipe or space. The following are all valid
|
|
151
|
+
* all will output this way when `--help` is used.
|
|
152
|
+
*
|
|
153
|
+
* "-p, --pepper"
|
|
154
|
+
* "-p|--pepper"
|
|
155
|
+
* "-p --pepper"
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* // simple boolean defaulting to false
|
|
159
|
+
* program.option('-p, --pepper', 'add pepper');
|
|
160
|
+
*
|
|
161
|
+
* --pepper
|
|
162
|
+
* program.pepper
|
|
163
|
+
* // => Boolean
|
|
164
|
+
*
|
|
165
|
+
* // simple boolean defaulting to true
|
|
166
|
+
* program.option('-C, --no-cheese', 'remove cheese');
|
|
167
|
+
*
|
|
168
|
+
* program.cheese
|
|
169
|
+
* // => true
|
|
170
|
+
*
|
|
171
|
+
* --no-cheese
|
|
172
|
+
* program.cheese
|
|
173
|
+
* // => false
|
|
174
|
+
*
|
|
175
|
+
* // required argument
|
|
176
|
+
* program.option('-C, --chdir <path>', 'change the working directory');
|
|
177
|
+
*
|
|
178
|
+
* --chdir /tmp
|
|
179
|
+
* program.chdir
|
|
180
|
+
* // => "/tmp"
|
|
181
|
+
*
|
|
182
|
+
* // optional argument
|
|
183
|
+
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
|
184
|
+
*
|
|
185
|
+
* @param {string} flags
|
|
186
|
+
* @param {string} [description]
|
|
187
|
+
* @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default
|
|
188
|
+
* @param {*} [defaultValue]
|
|
189
|
+
* @returns {Command} for chaining
|
|
190
|
+
*/
|
|
191
|
+
option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command;
|
|
192
|
+
option(flags: string, description?: string, defaultValue?: any): Command;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Allow unknown options on the command line.
|
|
196
|
+
*
|
|
197
|
+
* @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options.
|
|
198
|
+
* @returns {Command} for chaining
|
|
199
|
+
*/
|
|
200
|
+
allowUnknownOption(arg?: boolean): Command;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Parse `argv`, settings options and invoking commands when defined.
|
|
204
|
+
*
|
|
205
|
+
* @param {string[]} argv
|
|
206
|
+
* @returns {Command} for chaining
|
|
207
|
+
*/
|
|
208
|
+
parse(argv: string[]): Command;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Parse options from `argv` returning `argv` void of these options.
|
|
212
|
+
*
|
|
213
|
+
* @param {string[]} argv
|
|
214
|
+
* @returns {ParseOptionsResult}
|
|
215
|
+
*/
|
|
216
|
+
parseOptions(argv: string[]): commander.ParseOptionsResult;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Return an object containing options as key-value pairs
|
|
220
|
+
*
|
|
221
|
+
* @returns {{[key: string]: any}}
|
|
222
|
+
*/
|
|
223
|
+
opts(): { [key: string]: any };
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Set the description to `str`.
|
|
227
|
+
*
|
|
228
|
+
* @param {string} str
|
|
229
|
+
* @param {{[argName: string]: string}} argsDescription
|
|
230
|
+
* @return {(Command | string)}
|
|
231
|
+
*/
|
|
232
|
+
description(str: string, argsDescription?: {[argName: string]: string}): Command;
|
|
233
|
+
description(): string;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Set an alias for the command.
|
|
237
|
+
*
|
|
238
|
+
* @param {string} alias
|
|
239
|
+
* @return {(Command | string)}
|
|
240
|
+
*/
|
|
241
|
+
alias(alias: string): Command;
|
|
242
|
+
alias(): string;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Set or get the command usage.
|
|
246
|
+
*
|
|
247
|
+
* @param {string} str
|
|
248
|
+
* @return {(Command | string)}
|
|
249
|
+
*/
|
|
250
|
+
usage(str: string): Command;
|
|
251
|
+
usage(): string;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Set the name of the command.
|
|
255
|
+
*
|
|
256
|
+
* @param {string} str
|
|
257
|
+
* @return {Command}
|
|
258
|
+
*/
|
|
259
|
+
name(str: string): Command;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Get the name of the command.
|
|
263
|
+
*
|
|
264
|
+
* @return {string}
|
|
265
|
+
*/
|
|
266
|
+
name(): string;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Output help information for this command.
|
|
270
|
+
*
|
|
271
|
+
* @param {(str: string) => string} [cb]
|
|
272
|
+
*/
|
|
273
|
+
outputHelp(cb?: (str: string) => string): void;
|
|
274
|
+
|
|
275
|
+
/** Output help information and exit.
|
|
276
|
+
*
|
|
277
|
+
* @param {(str: string) => string} [cb]
|
|
278
|
+
*/
|
|
279
|
+
help(cb?: (str: string) => string): never;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
declare namespace commander {
|
|
285
|
+
|
|
286
|
+
type Command = local.Command
|
|
287
|
+
|
|
288
|
+
type Option = local.Option
|
|
289
|
+
|
|
290
|
+
interface CommandOptions {
|
|
291
|
+
noHelp?: boolean;
|
|
292
|
+
isDefault?: boolean;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
interface ParseOptionsResult {
|
|
296
|
+
args: string[];
|
|
297
|
+
unknown: string[];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
interface CommanderStatic extends Command {
|
|
301
|
+
Command: typeof local.Command;
|
|
302
|
+
Option: typeof local.Option;
|
|
303
|
+
CommandOptions: CommandOptions;
|
|
304
|
+
ParseOptionsResult: ParseOptionsResult;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
declare const commander: commander.CommanderStatic;
|
|
310
|
+
export = commander;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 老雷
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
[](http://badge.fury.io/js/xss)
|
|
2
|
+
[](http://travis-ci.org/leizongmin/js-css-filter)
|
|
3
|
+
[](https://david-dm.org/leizongmin/js-css-filter)
|
|
4
|
+
[](https://coveralls.io/r/leizongmin/js-css-filter?branch=master)
|
|
5
|
+
|
|
6
|
+
# cssfilter
|
|
7
|
+
Sanitize untrusted CSS with a configuration specified by a Whitelist. 根据白名单过滤CSS
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## 安装
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
$ npm install cssfilter --save
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 使用方法
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
var cssfilter = require('cssfilter');
|
|
21
|
+
var css = cssfilter('position:fixed; /* this is comments */ width:100px; height:100px; background:#aaa;');
|
|
22
|
+
console.log(css);
|
|
23
|
+
// 输出:width:100px; height:100px; background:#aaa;
|
|
24
|
+
// 因为position不在白名单允许范围
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
或者:
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
options = {
|
|
31
|
+
// 白名单,可选
|
|
32
|
+
whiteList: {
|
|
33
|
+
a: true, // true表示允许
|
|
34
|
+
b: /^fixed|relative$/, // 正则test()返回true表示允许
|
|
35
|
+
c: function (value) {
|
|
36
|
+
// 返回true表示允许
|
|
37
|
+
},
|
|
38
|
+
d: false // 除以上三个以外,所有值均表示不允许
|
|
39
|
+
},
|
|
40
|
+
// 当匹配到一个在白名单中的属性时
|
|
41
|
+
onAttr: function (name, value, options) {
|
|
42
|
+
// name为属性名
|
|
43
|
+
// value为属性值
|
|
44
|
+
// 返回字符串表示覆盖此段CSS
|
|
45
|
+
// 不返回任何值表示使用默认生成方法,即 name:value
|
|
46
|
+
},
|
|
47
|
+
// 当匹配到一个不在白名单中的属性时
|
|
48
|
+
onIgnoreAttr: function (name, value, options) {
|
|
49
|
+
// name为属性名
|
|
50
|
+
// value为属性值
|
|
51
|
+
// 返回字符串表示覆盖此段CSS
|
|
52
|
+
// 不返回任何值表示使用默认生成方法,即将此段CSS去掉
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
mycss = new cssfilter.FilterCSS(options);
|
|
56
|
+
// then apply mycss.process()
|
|
57
|
+
css = mycss.process('position:fixed; width:100px; height:100px; background:#aaa;');
|
|
58
|
+
console.log(css);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
The MIT License (MIT)
|
|
66
|
+
|
|
67
|
+
Copyright (c) 2015-2016 Zongmin Lei(雷宗民) <leizongmin@gmail.com>
|
|
68
|
+
|
|
69
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
70
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
71
|
+
in the Software without restriction, including without limitation the rights
|
|
72
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
73
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
74
|
+
furnished to do so, subject to the following conditions:
|
|
75
|
+
|
|
76
|
+
The above copyright notice and this permission notice shall be included in all
|
|
77
|
+
copies or substantial portions of the Software.
|
|
78
|
+
|
|
79
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
80
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
81
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
82
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
83
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
84
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
85
|
+
SOFTWARE.
|
|
86
|
+
```
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cssfilter
|
|
3
|
+
*
|
|
4
|
+
* @author 老雷<leizongmin@gmail.com>
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var DEFAULT = require('./default');
|
|
8
|
+
var parseStyle = require('./parser');
|
|
9
|
+
var _ = require('./util');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 返回值是否为空
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} obj
|
|
16
|
+
* @return {Boolean}
|
|
17
|
+
*/
|
|
18
|
+
function isNull (obj) {
|
|
19
|
+
return (obj === undefined || obj === null);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 浅拷贝对象
|
|
24
|
+
*
|
|
25
|
+
* @param {Object} obj
|
|
26
|
+
* @return {Object}
|
|
27
|
+
*/
|
|
28
|
+
function shallowCopyObject (obj) {
|
|
29
|
+
var ret = {};
|
|
30
|
+
for (var i in obj) {
|
|
31
|
+
ret[i] = obj[i];
|
|
32
|
+
}
|
|
33
|
+
return ret;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 创建CSS过滤器
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} options
|
|
40
|
+
* - {Object} whiteList
|
|
41
|
+
* - {Function} onAttr
|
|
42
|
+
* - {Function} onIgnoreAttr
|
|
43
|
+
* - {Function} safeAttrValue
|
|
44
|
+
*/
|
|
45
|
+
function FilterCSS (options) {
|
|
46
|
+
options = shallowCopyObject(options || {});
|
|
47
|
+
options.whiteList = options.whiteList || DEFAULT.whiteList;
|
|
48
|
+
options.onAttr = options.onAttr || DEFAULT.onAttr;
|
|
49
|
+
options.onIgnoreAttr = options.onIgnoreAttr || DEFAULT.onIgnoreAttr;
|
|
50
|
+
options.safeAttrValue = options.safeAttrValue || DEFAULT.safeAttrValue;
|
|
51
|
+
this.options = options;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
FilterCSS.prototype.process = function (css) {
|
|
55
|
+
// 兼容各种奇葩输入
|
|
56
|
+
css = css || '';
|
|
57
|
+
css = css.toString();
|
|
58
|
+
if (!css) return '';
|
|
59
|
+
|
|
60
|
+
var me = this;
|
|
61
|
+
var options = me.options;
|
|
62
|
+
var whiteList = options.whiteList;
|
|
63
|
+
var onAttr = options.onAttr;
|
|
64
|
+
var onIgnoreAttr = options.onIgnoreAttr;
|
|
65
|
+
var safeAttrValue = options.safeAttrValue;
|
|
66
|
+
|
|
67
|
+
var retCSS = parseStyle(css, function (sourcePosition, position, name, value, source) {
|
|
68
|
+
|
|
69
|
+
var check = whiteList[name];
|
|
70
|
+
var isWhite = false;
|
|
71
|
+
if (check === true) isWhite = check;
|
|
72
|
+
else if (typeof check === 'function') isWhite = check(value);
|
|
73
|
+
else if (check instanceof RegExp) isWhite = check.test(value);
|
|
74
|
+
if (isWhite !== true) isWhite = false;
|
|
75
|
+
|
|
76
|
+
// 如果过滤后 value 为空则直接忽略
|
|
77
|
+
value = safeAttrValue(name, value);
|
|
78
|
+
if (!value) return;
|
|
79
|
+
|
|
80
|
+
var opts = {
|
|
81
|
+
position: position,
|
|
82
|
+
sourcePosition: sourcePosition,
|
|
83
|
+
source: source,
|
|
84
|
+
isWhite: isWhite
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
if (isWhite) {
|
|
88
|
+
|
|
89
|
+
var ret = onAttr(name, value, opts);
|
|
90
|
+
if (isNull(ret)) {
|
|
91
|
+
return name + ':' + value;
|
|
92
|
+
} else {
|
|
93
|
+
return ret;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
} else {
|
|
97
|
+
|
|
98
|
+
var ret = onIgnoreAttr(name, value, opts);
|
|
99
|
+
if (!isNull(ret)) {
|
|
100
|
+
return ret;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return retCSS;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
module.exports = FilterCSS;
|