Skip to content

Commit

Permalink
Remove line comments to fix #1796
Browse files Browse the repository at this point in the history
Co-authored-by: vishal diyora <[email protected]>
  • Loading branch information
vishal6557 and vishal diyora authored Dec 3, 2023
1 parent 4493120 commit a55b650
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/16comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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] = '';
Expand All @@ -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 /*! ... */
Expand Down
22 changes: 22 additions & 0 deletions test/test1796.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
2 changes: 1 addition & 1 deletion test/test221.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit a55b650

Please sign in to comment.