Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Parsing for qualifiers with colon characters #1277

Merged
merged 13 commits into from
May 24, 2023
16 changes: 12 additions & 4 deletions src/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
};
}

Expand Down
7 changes: 7 additions & 0 deletions test/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down