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
14 changes: 11 additions & 3 deletions src/mutation.ts
Original file line number Diff line number Diff line change
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: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend setting qualifier to undefined so that this code works the same way as before when the string doesn't contain a colon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that too, however the ParsedColumn interface does not declare undefined as an acceptable type for qualifier at https://github.com/googleapis/nodejs-bigtable/blob/main/src/mutation.ts#L35.

Adding undefined here would solve this:

export interface ParsedColumn {
  family: string | null;
  qualifier: string | null | undefined;
}
};
}

return {
family: parts[0],
qualifier: parts[1],
family: columnName.slice(0, colonIdx),
qualifier: columnName.slice(colonIdx + 1),
};
}

Expand Down
2 changes: 1 addition & 1 deletion test/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ describe('Bigtable/Mutation', () => {
const parsed = Mutation.parseColumnName('a');

assert.strictEqual(parsed.family, 'a');
assert.strictEqual(parsed.qualifier, undefined);
assert.strictEqual(parsed.qualifier, null);
});
});

Expand Down
Loading