From b80f5338ae1721659c61e48d80ba976c148c8087 Mon Sep 17 00:00:00 2001 From: Krishanu Dutta Bhuyan Date: Wed, 24 May 2023 18:57:22 +0530 Subject: [PATCH] fix: Parsing for qualifiers with colon characters (#1277) * Fix parsing for qualifiers with colon characters * Update ci.yaml * fix: Support names with no qualifier * revert: remove workflow_dispatch * fix: Update test to check null qualifiers instead of undefined * fix: Respect column names without qualifiers * fix: Clean up for lint errors * fix: Remove remaining trailing space * revert: "fix: Update test to check null qualifiers instead of undefined" This reverts commit 1275dd56cd8aea668703e1f83daecfd14d5199f6. * fix: Allow undefined qualifiers in ParsedColumn * test: Add test for qualifier names with colons --------- Co-authored-by: danieljbruce --- src/mutation.ts | 16 ++++++++++++---- test/mutation.ts | 7 +++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/mutation.ts b/src/mutation.ts index a592c21ab..0aef34202 100644 --- a/src/mutation.ts +++ b/src/mutation.ts @@ -32,7 +32,7 @@ export type Value = string | number | boolean; export interface ParsedColumn { family: string | null; - qualifier: string | null; + qualifier: string | null | undefined; } export interface ConvertFromBytesOptions { userOptions?: ConvertFromBytesUserOptions; @@ -380,11 +380,19 @@ export class Mutation { * @private */ static parseColumnName(columnName: string): ParsedColumn { - const parts = columnName.split(':'); + const colonIdx = columnName.indexOf(':'); + + if (colonIdx === -1) { + // columnName does not contain ':' + return { + family: columnName, + qualifier: undefined, + }; + } return { - family: parts[0], - qualifier: parts[1], + family: columnName.slice(0, colonIdx), + qualifier: columnName.slice(colonIdx + 1), }; } diff --git a/test/mutation.ts b/test/mutation.ts index 52df95c28..7566a7496 100644 --- a/test/mutation.ts +++ b/test/mutation.ts @@ -465,6 +465,13 @@ describe('Bigtable/Mutation', () => { assert.strictEqual(parsed.family, 'a'); assert.strictEqual(parsed.qualifier, undefined); }); + + it('should parse a qualifier name with colons', () => { + const parsed = Mutation.parseColumnName('a:b:c'); + + assert.strictEqual(parsed.family, 'a'); + assert.strictEqual(parsed.qualifier, 'b:c'); + }); }); describe('toProto', () => {