Skip to content

Commit

Permalink
fix ReDoS vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Oct 25, 2018
1 parent 85ded30 commit 791b7d8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -2,5 +2,5 @@ before_script: "npm install --dev"
script: "npm test"
language: node_js
node_js:
- 0.8
- 0.10
- node
- lts/*
62 changes: 40 additions & 22 deletions package.json
@@ -1,23 +1,41 @@
{ "name": "slug"
, "description": "slugifies even utf-8 chars!"
, "version": "0.9.1"
, "homepage": "https://github.com/dodo/node-slug"
, "author": "dodo (https://github.com/dodo)"
, "repository": {"type": "git", "url": "git://github.com/dodo/node-slug.git"}
, "main": "slug.js"
, "engines": {"node": ">= 0.4.x"}
, "keywords": ["slugify", "slug", "string", "utf8", "utf-8", "unicode", "url"]
, "scripts": {
"test": "./node_modules/.bin/mocha ./test/*.test.* --require should --reporter spec --colors --compilers coffee:coffee-script/register"}
, "dependencies": {
"unicode": ">= 0.3.1"}
, "devDependencies": {
"mocha": "~1.17.1",
"should": "~3.1.2",
"coffee-script": "~1.7.1"}
, "bin": {
"slug": "bin/slug.js"}
, "licenses" : [
{ "type": "MIT" ,
"url": "http://github.com/dodo/node-slug/raw/master/LICENSE"} ]
{
"name": "slug",
"description": "slugifies even utf-8 chars!",
"version": "0.9.1",
"homepage": "https://github.com/Trott/node-slug",
"author": "dodo (https://github.com/dodo)",
"repository": {
"type": "git",
"url": "git://github.com/Trott/node-slug.git"
},
"main": "slug.js",
"keywords": [
"slugify",
"slug",
"string",
"utf8",
"utf-8",
"unicode",
"url"
],
"scripts": {
"test": "./node_modules/.bin/mocha ./test/*.test.* --require should --reporter spec --colors --compilers coffee:coffee-script/register"
},
"dependencies": {
"unicode": ">= 0.3.1"
},
"devDependencies": {
"coffee-script": "~1.7.1",
"mocha": "^5.2.0",
"should": "~3.1.2"
},
"bin": {
"slug": "bin/slug.js"
},
"licenses": [
{
"type": "MIT",
"url": "http://github.com/Trott/node-slug/raw/master/LICENSE"
}
]
}
4 changes: 2 additions & 2 deletions slug.js
Expand Up @@ -54,14 +54,14 @@ function slug(string, opts) {
for(var j = 0, rl = removelist.length; j < rl; j++) {
char = char.replace(removelist[j], '');
}
char = char.replace(/^\s+|\s+$/g, '');
char = char.trim();
}
}
char = char.replace(/[^\w\s\-\.\_~]/g, ''); // allowed
if (opts.remove) char = char.replace(opts.remove, ''); // add flavour
result += char;
}
result = result.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
result = result.trim();
result = result.replace(/[-\s]+/g, opts.replacement); // convert spaces
result = result.replace(opts.replacement+"$",''); // remove trailing separator
if (opts.lower)
Expand Down

0 comments on commit 791b7d8

Please sign in to comment.