Skip to content

Commit 3074fa9

Browse files
committed
fix: fix unexpected parser action
Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>
1 parent 3e1fa9d commit 3074fa9

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/config.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export class Config implements ConfigInterface {
9191
}
9292

9393
private parseBuffer(buf: Buffer): void {
94-
const lines = buf.toString().split('\n');
94+
const lines = buf
95+
.toString()
96+
.split('\n')
97+
.filter((v) => v);
9598
const linesCount = lines.length;
9699
let section = '';
97100
let currentLine = '';
@@ -123,15 +126,11 @@ export class Config implements ConfigInterface {
123126
let shouldWrite = false;
124127
if (line.includes(Config.DEFAULT_MULTI_LINE_SEPARATOR)) {
125128
currentLine += line.substring(0, line.length - 1).trim();
126-
// when the last line has a "\" string
127-
if (lineNumber + 1 === linesCount) {
128-
shouldWrite = true;
129-
}
130129
} else {
131130
currentLine += line;
132131
shouldWrite = true;
133132
}
134-
if (shouldWrite) {
133+
if (shouldWrite || lineNumber === linesCount) {
135134
this.write(section, lineNumber, currentLine);
136135
currentLine = '';
137136
}

test/config/config.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ describe('multi-line test', () => {
2323
expect(config.get('multi5::name')).toEqual('r.sub==p.sub&&r.obj==p.obj');
2424
});
2525

26+
it('should config.get("multi6::name") to equal r.sub==p.sub&&r.obj==p.obj&&r.tex==p.tex', function () {
27+
expect(config.get('multi6::name')).toEqual('r.sub==p.sub&&r.obj==p.obj&&r.tex==p.tex');
28+
});
29+
2630
it('should config.get("mysql::mysql.master.host") to equal 10.0.0.1', function () {
2731
expect(config.get('mysql::mysql.master.host')).toEqual('10.0.0.1');
2832
});

test/config/testini.ini

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ name = \
4343

4444
[multi5]
4545
name = r.sub==p.sub \
46-
&&r.obj==p.obj\
46+
&&r.obj==p.obj \
4747
\
48+
49+
[multi6]
50+
name = r.sub==p.sub \
51+
&&r.obj==p.obj \
52+
&&r.tex==p.tex

0 commit comments

Comments
 (0)