Skip to content

Commit 47130e8

Browse files
committed
Allow blob to be empty
1 parent 892b600 commit 47130e8

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/vimscript/expression/evaluate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,8 @@ export class EvaluationContext {
878878
return bool(x.items.length === 0);
879879
case 'dict_val':
880880
return bool(x.items.size === 0);
881-
// TODO:
882-
// case 'blob':
881+
case 'blob':
882+
return bool(x.data.byteLength === 0);
883883
default:
884884
return bool(false);
885885
}

src/vimscript/expression/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838

3939
// TODO: Support dots between bytes
4040
const blobParser: Parser<BlobValue> = regexp(/0[z]/i).then(
41-
regexp(/[0-1a-z]+/i).map<BlobValue>((hexData) => {
41+
regexp(/[0-1a-z]*/i).map<BlobValue>((hexData) => {
4242
if (hexData.length % 2 !== 0) {
4343
throw VimError.fromCode(ErrorCode.BlobLiteralShouldHaveAnEvenNumberOfHexCharacters);
4444
}

test/vimscript/expression.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,14 @@ suite('Vimscript expressions', () => {
589589
exprTest("empty('')", { value: bool(true) });
590590
exprTest('empty([])', { value: bool(true) });
591591
exprTest('empty({})', { value: bool(true) });
592+
exprTest('empty(0z)', { value: bool(true) });
592593

593594
exprTest('empty(1)', { value: bool(false) });
594595
exprTest('empty(1.0)', { value: bool(false) });
595596
exprTest("empty('xyz')", { value: bool(false) });
596597
exprTest('empty([0])', { value: bool(false) });
597598
exprTest("empty({'k': 'v'})", { value: bool(false) });
599+
exprTest('empty(0z00)', { value: bool(false) });
598600
});
599601

600602
suite('function', () => {

0 commit comments

Comments
 (0)