Skip to content

Commit bbb76fb

Browse files
author
Hannu Pelkonen
committed
Add tests for windows linebreak support SC5#530
1 parent 019c4cb commit bbb76fb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/modules/kss-additional-params.js

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ function trimLinebreaks(str) {
88
return str.replace(/^[\r\n]+|[\r\n]+$/g, '');
99
}
1010

11+
function standardizeLinebreaks(str) {
12+
// Replace windows and mac line endings to unix line endings convention
13+
if (!str) {
14+
return str;
15+
}
16+
return str.replace(/\r?\n|\r/g, '\n');
17+
}
18+
1119
// A list of params which need values parsing
1220
var ComplexParams = [
1321
'sg-angular-directive'
@@ -23,6 +31,7 @@ module.exports = {
2331
additionalKssParams = {},
2432
_this = this;
2533

34+
comment = standardizeLinebreaks(comment);
2635
comment = trimLinebreaks(comment);
2736

2837
comment.split('\n\n').forEach(function(markUpBlock) {

test/unit/modules/kss-additional-params.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ describe('Parsing KSS additional params', function() {
2323
expect(params).eql(result);
2424
});
2525

26+
it('should parse windows linebreaks correctly', function() {
27+
// jscs:disable
28+
var str = "/*\r\n// sg-param:\r\n// Value\r\n*/\r\n";
29+
var str2 = "/*\r// sg-param:\r// Value\r*/\r";
30+
// jscs:enable
31+
result = { 'sg-param': ' Value' },
32+
expect(kssAdditionalParams.get(str)).eql(result);
33+
expect(kssAdditionalParams.get(str2)).eql(result);
34+
});
35+
2636
it('Should parse from multiline-commented block', function() {
2737
var str = '' +
2838
'/*\n' +

0 commit comments

Comments
 (0)