Skip to content

Commit 9b4155d

Browse files
authored
Fixed a bug that cannot properly handle invalid G-code words (#3) (#5)
* Fixed a bug that cannot properly handle invalid G-code words (#3) * Remove redundant files
1 parent 12f427a commit 9b4155d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const parseLine = (() => {
7272
const re3 = new RegExp(/\s+/g);
7373
return (line => line.replace(re1, '').replace(re2, '').replace(re3, ''));
7474
})();
75-
const re = /(%.*)|({.*)|((?:\$\$)|(?:\$[a-zA-Z0-9#]*))|([a-zA-Z][0-9\+\-\.]*)|(\*[0-9]+)/igm;
75+
const re = /(%.*)|({.*)|((?:\$\$)|(?:\$[a-zA-Z0-9#]*))|([a-zA-Z][0-9\+\-\.]+)|(\*[0-9]+)/igm;
7676

7777
return (line, options) => {
7878
options = options || {};
@@ -105,7 +105,7 @@ const parseLine = (() => {
105105
continue;
106106
}
107107

108-
// Parser JSON commands for TinyG and g2core
108+
// Parse JSON commands for TinyG and g2core
109109
if (letter === '{') {
110110
result.cmds = (result.cmds || []).concat(line.trim());
111111
continue;

test/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ describe('gcode-parser', () => {
6363
});
6464
});
6565

66+
describe('Invalid G-code words', () => {
67+
it('should ignore invalid g-code words', (done) => {
68+
const data = parseLine('messed up');
69+
expect(data).to.be.an('object');
70+
expect(data.line).to.be.equal('messed up');
71+
expect(data.words).to.be.empty;
72+
done();
73+
});
74+
});
75+
6676
describe('Commands', () => {
6777
it('should be able to parse $ command (e.g. Grbl).', (done) => {
6878
const data = parseLine('$H $C');

0 commit comments

Comments
 (0)