better code injection handling for js

This commit is contained in:
wing328
2016-06-28 23:17:28 +08:00
parent acc28495e8
commit aec2f4e27c
1354 changed files with 313854 additions and 109 deletions

View File

@@ -0,0 +1,11 @@
'use strict';
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
module.exports = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}
return str.replace(matchOperatorsRe, '\\$&');
};

View File

@@ -0,0 +1,94 @@
{
"_args": [
[
"escape-string-regexp@1.0.2",
"/Users/williamcheng/Code/may2016/swagger-codegen/samples/client/petstore-security-test/javascript/node_modules/mocha"
]
],
"_from": "escape-string-regexp@1.0.2",
"_id": "escape-string-regexp@1.0.2",
"_inCache": true,
"_installable": true,
"_location": "/escape-string-regexp",
"_npmUser": {
"email": "jappelman@xebia.com",
"name": "jbnicolai"
},
"_npmVersion": "1.4.23",
"_phantomChildren": {},
"_requested": {
"name": "escape-string-regexp",
"raw": "escape-string-regexp@1.0.2",
"rawSpec": "1.0.2",
"scope": null,
"spec": "1.0.2",
"type": "version"
},
"_requiredBy": [
"/mocha"
],
"_resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz",
"_shasum": "4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1",
"_shrinkwrap": null,
"_spec": "escape-string-regexp@1.0.2",
"_where": "/Users/williamcheng/Code/may2016/swagger-codegen/samples/client/petstore-security-test/javascript/node_modules/mocha",
"author": {
"email": "sindresorhus@gmail.com",
"name": "Sindre Sorhus",
"url": "http://sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/escape-string-regexp/issues"
},
"dependencies": {},
"description": "Escape RegExp special characters",
"devDependencies": {
"mocha": "*"
},
"directories": {},
"dist": {
"shasum": "4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1",
"tarball": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz"
},
"engines": {
"node": ">=0.8.0"
},
"files": [
"index.js"
],
"gitHead": "0587ee0ee03ea3fcbfa3c15cf67b47f214e20987",
"homepage": "https://github.com/sindresorhus/escape-string-regexp",
"keywords": [
"characters",
"escape",
"expression",
"re",
"regex",
"regexp",
"regular",
"special",
"str",
"string"
],
"license": "MIT",
"maintainers": [
{
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
},
{
"name": "jbnicolai",
"email": "jappelman@xebia.com"
}
],
"name": "escape-string-regexp",
"optionalDependencies": {},
"repository": {
"type": "git",
"url": "https://github.com/sindresorhus/escape-string-regexp"
},
"scripts": {
"test": "mocha"
},
"version": "1.0.2"
}

View File

@@ -0,0 +1,27 @@
# escape-string-regexp [![Build Status](https://travis-ci.org/sindresorhus/escape-string-regexp.svg?branch=master)](https://travis-ci.org/sindresorhus/escape-string-regexp)
> Escape RegExp special characters
## Install
```sh
$ npm install --save escape-string-regexp
```
## Usage
```js
var escapeStringRegexp = require('escape-string-regexp');
var escapedString = escapeStringRegexp('how much $ for a unicorn?');
//=> how much \$ for a unicorn\?
new RegExp(escapedString);
```
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)