Skip to content

Commit 90e85af

Browse files
Follow up of pull request #626 (#627)
* Fix ReDoS in dice_coefficient Fix ReDos in `dice_coefficient.js` This related issue addresses #613 * Repaired a test for Dice coefficient Co-authored-by: Yeting Li <[email protected]>
1 parent 7689c9a commit 90e85af

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/natural/distance/dice_coefficient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function intersect (set1, set2) {
5151
function sanitize (str) {
5252
// Turn characters to lower string, remove space at the beginning and end,
5353
// replace multiple spaces in the middle by single spaces
54-
return str.toLowerCase().replace(/^\s+|\s+$/g, '').replace(/s+/g, ' ')
54+
return str.toLowerCase().replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '')
5555
}
5656

5757
function diceCoefficient (str1, str2) {

spec/dice_coefficient_spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ describe('dice', function () {
3232
it('should compare complete texts', function () {
3333
const text1 = require('./test_data/Wikipedia_EN_FrenchRevolution.json').text
3434
const text2 = require('./test_data/Wikipedia_EN_InfluenceOfTheFrenchRevolution.json').text
35-
expect(dice(text1, text2)).toBe(0.7897503285151117)
35+
expect(dice(text1, text2)).toBe(0.7939374395356337)
3636
})
3737
})

0 commit comments

Comments
 (0)