diff --git a/src/16comments.js b/src/16comments.js index 4debe00272..b4dbd4f439 100755 --- a/src/16comments.js +++ b/src/16comments.js @@ -5,7 +5,7 @@ @return {string} Based om the https://github.com/lehni/uncomment.js/blob/master/uncomment.js I just replaced JavaScript's '//' to SQL's '--' and remove other stuff - + @todo Fixed [aaa/*bbb] for column names @todo Bug if -- comments in the last line @todo Check if it possible to model it with Jison parser @@ -45,7 +45,7 @@ alasql.utils.uncomment = function (str) { // characterClass = false; // } else if (str[i] === '/' && unescaped && !characterClass) { // regularExpression = false; - // } + // } // */ } else if (blockComment) { // Is the block comment closing? @@ -62,7 +62,7 @@ alasql.utils.uncomment = function (str) { } } else if (lineComment) { // One-line comments end with the line-break - if (str[i + 1] === '\n' || str[i + 1] === '\r') { + if (str[i + 1] === '\n' || str[i + 1] === '\r' || str.length - 2 === i) { lineComment = false; } str[i] = ''; @@ -73,9 +73,9 @@ alasql.utils.uncomment = function (str) { } else if (str[i] === '[' && str[i - 1] !== '@') { quote = true; quoteSign = ']'; - // } else if (str[i] === '-' && str[i + 1] === '-') { - // str[i] = ''; - // lineComment = true; + } else if (str[i] === '-' && str[i + 1] === '-') { + str[i] = ''; + lineComment = true; } else if (str[i] === '/' && str[i + 1] === '*') { // Do not filter out conditional comments /*@ ... */ // and comments marked as protected /*! ... */ diff --git a/test/test1796.js b/test/test1796.js new file mode 100644 index 0000000000..56514417a0 --- /dev/null +++ b/test/test1796.js @@ -0,0 +1,22 @@ +if (typeof exports === 'object') { + var assert = require('assert'); + var alasql = require('..'); +} else { + __dirname = '.'; +} + +describe('Test 1796 Multi-line comments', function () { + it('1. /* */ and -- style comments', function (done) { + var res = alasql.utils.uncomment('one /* two \n three */ four \n five -- six\nseven'); + // console.log(res); + assert.equal(res, 'one four \n five \nseven'); + done(); + }); + + it('2. /* */', function (done) { + var res = alasql.utils.uncomment('SELECT /* xxx */ VALUE /* blahblah \n tuturututu */ 1'); + // console.log(res); + assert.equal(res, 'SELECT VALUE 1'); + done(); + }); +}); diff --git a/test/test221.js b/test/test221.js index bb70420e30..f060b191f0 100644 --- a/test/test221.js +++ b/test/test221.js @@ -6,7 +6,7 @@ if (typeof exports === 'object') { } describe('Test 221 Multi-line comments', function () { - it.skip('1. /* */ and -- style comments', function (done) { + it('1. /* */ and -- style comments', function (done) { var res = alasql.utils.uncomment('one /* two \n three */ four \n five -- six\nseven'); // console.log(res); assert.equal(res, 'one four \n five \nseven');