Skip to content

Commit c70e6dd

Browse files
committed
fix: handle mismatched brackets
weizhenye/ASS#58
1 parent 174cbb0 commit c70e6dd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/parser/text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parseDrawing } from './drawing.js';
22
import { parseTags } from './tags.js';
33

44
export function parseText(text) {
5-
const pairs = text.split(/{([^{}]*?)}/);
5+
const pairs = text.split(/{(.*?)}/);
66
const parsed = [];
77
if (pairs[0].length) {
88
parsed.push({ tags: [], text: pairs[0], drawing: [] });

test/parser/text.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,12 @@ describe('text parser', () => {
6464
it('should detect whether it is drawing', () => {
6565
expect(parseText('{\\p1\\p0}m 0 0 l 1 0').parsed[0].drawing).to.deep.equal([]);
6666
});
67+
68+
it('should handle mismatched brackets', () => {
69+
expect(parseText('{ a { b }c')).to.deep.equal({
70+
raw: '{ a { b }c',
71+
combined: 'c',
72+
parsed: [{ tags: [], text: 'c', drawing: [] }],
73+
});
74+
});
6775
});

0 commit comments

Comments
 (0)