Skip to content

Commit 791b7d8

Browse files
committed
fix ReDoS vulnerability
1 parent 85ded30 commit 791b7d8

3 files changed

Lines changed: 44 additions & 26 deletions

File tree

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ before_script: "npm install --dev"
22
script: "npm test"
33
language: node_js
44
node_js:
5-
- 0.8
6-
- 0.10
5+
- node
6+
- lts/*

package.json

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
1-
{ "name": "slug"
2-
, "description": "slugifies even utf-8 chars!"
3-
, "version": "0.9.1"
4-
, "homepage": "https://github.com/dodo/node-slug"
5-
, "author": "dodo (https://github.com/dodo)"
6-
, "repository": {"type": "git", "url": "git://github.com/dodo/node-slug.git"}
7-
, "main": "slug.js"
8-
, "engines": {"node": ">= 0.4.x"}
9-
, "keywords": ["slugify", "slug", "string", "utf8", "utf-8", "unicode", "url"]
10-
, "scripts": {
11-
"test": "./node_modules/.bin/mocha ./test/*.test.* --require should --reporter spec --colors --compilers coffee:coffee-script/register"}
12-
, "dependencies": {
13-
"unicode": ">= 0.3.1"}
14-
, "devDependencies": {
15-
"mocha": "~1.17.1",
16-
"should": "~3.1.2",
17-
"coffee-script": "~1.7.1"}
18-
, "bin": {
19-
"slug": "bin/slug.js"}
20-
, "licenses" : [
21-
{ "type": "MIT" ,
22-
"url": "http://github.com/dodo/node-slug/raw/master/LICENSE"} ]
1+
{
2+
"name": "slug",
3+
"description": "slugifies even utf-8 chars!",
4+
"version": "0.9.1",
5+
"homepage": "https://github.com/Trott/node-slug",
6+
"author": "dodo (https://github.com/dodo)",
7+
"repository": {
8+
"type": "git",
9+
"url": "git://github.com/Trott/node-slug.git"
10+
},
11+
"main": "slug.js",
12+
"keywords": [
13+
"slugify",
14+
"slug",
15+
"string",
16+
"utf8",
17+
"utf-8",
18+
"unicode",
19+
"url"
20+
],
21+
"scripts": {
22+
"test": "./node_modules/.bin/mocha ./test/*.test.* --require should --reporter spec --colors --compilers coffee:coffee-script/register"
23+
},
24+
"dependencies": {
25+
"unicode": ">= 0.3.1"
26+
},
27+
"devDependencies": {
28+
"coffee-script": "~1.7.1",
29+
"mocha": "^5.2.0",
30+
"should": "~3.1.2"
31+
},
32+
"bin": {
33+
"slug": "bin/slug.js"
34+
},
35+
"licenses": [
36+
{
37+
"type": "MIT",
38+
"url": "http://github.com/Trott/node-slug/raw/master/LICENSE"
39+
}
40+
]
2341
}

slug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ function slug(string, opts) {
5454
for(var j = 0, rl = removelist.length; j < rl; j++) {
5555
char = char.replace(removelist[j], '');
5656
}
57-
char = char.replace(/^\s+|\s+$/g, '');
57+
char = char.trim();
5858
}
5959
}
6060
char = char.replace(/[^\w\s\-\.\_~]/g, ''); // allowed
6161
if (opts.remove) char = char.replace(opts.remove, ''); // add flavour
6262
result += char;
6363
}
64-
result = result.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
64+
result = result.trim();
6565
result = result.replace(/[-\s]+/g, opts.replacement); // convert spaces
6666
result = result.replace(opts.replacement+"$",''); // remove trailing separator
6767
if (opts.lower)

0 commit comments

Comments
 (0)