Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fix 1556: Update utils.clean to handle newlines in func declarations

Daniel St. Julesd15caceb7e93
diff --git a/lib/utils.js b/lib/utils.js
index cef8d0fe..c1393a9c 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -237,7 +237,7 @@ exports.slug = function(str){
exports.clean = function(str) {
str = str
.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '')
- .replace(/^function *\(.*\) *{|\(.*\) *=> *{?/, '')
+ .replace(/^function *\(.*\)\s*{|\(.*\) *=> *{?/, '')
.replace(/\s+\}$/, '');
var spaces = str.match(/^\n?( *)/)[1].length
diff --git a/mocha.js b/mocha.js
index 017b9018..bcca1acb 100755
--- a/mocha.js
+++ b/mocha.js
@@ -5932,7 +5932,7 @@ exports.slug = function(str){
exports.clean = function(str) {
str = str
.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '')
- .replace(/^function *\(.*\) *{|\(.*\) *=> *{?/, '')
+ .replace(/^function *\(.*\)\s*{|\(.*\) *=> *{?/, '')
.replace(/\s+\}$/, '');
var spaces = str.match(/^\n?( *)/)[1].length
diff --git a/test/utils.js b/test/utils.js
index 780d8c32..524a0e05 100644
--- a/test/utils.js
+++ b/test/utils.js
@@ -8,6 +8,10 @@ describe('utils', function() {
clean('function (one, two, three) {\n//code\n}').should.equal('//code');
});
+ it('should handle newlines in the function declaration', function() {
+ clean('function (one, two, three)\n {\n//code\n}').should.equal('//code');
+ });
+
it('should remove space character indentation from the function body', function() {
clean(' //line1\n //line2').should.equal('//line1\n //line2');
});