From 2708a76501348b940cc09ce7546b6b8e0c826c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Breitbart?= Date: Thu, 13 Sep 2018 15:44:26 +0200 Subject: [PATCH] fix next() invocation; handle wild matches --- src/Linkifier.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Linkifier.ts b/src/Linkifier.ts index a2135550..9ff8b823 100644 --- a/src/Linkifier.ts +++ b/src/Linkifier.ts @@ -93,8 +93,8 @@ export class Linkifier extends EventEmitter implements ILinkifier { // we skip those later in _doLinkifyRow const linesIterator = this._terminal.buffer.contents(false, absoluteRowIndexStart, this._terminal.buffer.ydisp + this._rowsToLinkify.end + 1); while (linesIterator.hasNext()) { + const lineData: any = linesIterator.next(true); for (let i = 0; i < this._linkMatchers.length; i++) { - const lineData: any = linesIterator.next(true); this._doLinkifyRow(lineData[0].first, lineData[1], this._linkMatchers[i]); } } @@ -182,6 +182,12 @@ export class Linkifier extends EventEmitter implements ILinkifier { let stringIndex = -1; while ((match = rex.exec(text)) !== null) { const uri = match[typeof matcher.matchIndex !== 'number' ? 0 : matcher.matchIndex]; + if (!uri) { + // something matched but does not comply with the given matchIndex + // since this is most likely a bug the regex itself we simply do nothing here + // TODO: should this be logged for debugging? + break; + } // due to complex regexes we cannot use match.index directly // instead we search the position of the match group in text again TODO: Can this be avoided?