Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue 1796 : utils.uncomment not removing "line" comments #1802

Merged
merged 4 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading