From bbb76fb058d3076e839ac608ef997fcc724694d9 Mon Sep 17 00:00:00 2001 From: Hannu Pelkonen Date: Mon, 30 Mar 2015 12:17:04 +0300 Subject: [PATCH] Add tests for windows linebreak support #530 --- lib/modules/kss-additional-params.js | 9 +++++++++ test/unit/modules/kss-additional-params.test.js | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/modules/kss-additional-params.js b/lib/modules/kss-additional-params.js index 7bf88575..57dca034 100644 --- a/lib/modules/kss-additional-params.js +++ b/lib/modules/kss-additional-params.js @@ -8,6 +8,14 @@ function trimLinebreaks(str) { return str.replace(/^[\r\n]+|[\r\n]+$/g, ''); } +function standardizeLinebreaks(str) { + // Replace windows and mac line endings to unix line endings convention + if (!str) { + return str; + } + return str.replace(/\r?\n|\r/g, '\n'); +} + // A list of params which need values parsing var ComplexParams = [ 'sg-angular-directive' @@ -23,6 +31,7 @@ module.exports = { additionalKssParams = {}, _this = this; + comment = standardizeLinebreaks(comment); comment = trimLinebreaks(comment); comment.split('\n\n').forEach(function(markUpBlock) { diff --git a/test/unit/modules/kss-additional-params.test.js b/test/unit/modules/kss-additional-params.test.js index 60527794..4cdc2d5d 100644 --- a/test/unit/modules/kss-additional-params.test.js +++ b/test/unit/modules/kss-additional-params.test.js @@ -23,6 +23,16 @@ describe('Parsing KSS additional params', function() { expect(params).eql(result); }); + it('should parse windows linebreaks correctly', function() { + // jscs:disable + var str = "/*\r\n// sg-param:\r\n// Value\r\n*/\r\n"; + var str2 = "/*\r// sg-param:\r// Value\r*/\r"; + // jscs:enable + result = { 'sg-param': ' Value' }, + expect(kssAdditionalParams.get(str)).eql(result); + expect(kssAdditionalParams.get(str2)).eql(result); + }); + it('Should parse from multiline-commented block', function() { var str = '' + '/*\n' +