mirror of https://github.com/grpc/grpc-node.git
Merge pull request #1195 from ortoo/master
grpc-js: fix error messages truncating at commas
This commit is contained in:
commit
9ec428bdd4
|
@ -36,6 +36,10 @@ function isBinaryKey(key: string): boolean {
|
|||
return key.endsWith('-bin');
|
||||
}
|
||||
|
||||
function isCustomMetadata(key: string): boolean {
|
||||
return !key.startsWith('grpc-');
|
||||
}
|
||||
|
||||
function normalizeKey(key: string): string {
|
||||
return key.toLowerCase();
|
||||
}
|
||||
|
@ -260,9 +264,13 @@ export class Metadata {
|
|||
result.add(key, Buffer.from(value, 'base64'));
|
||||
});
|
||||
} else if (values !== undefined) {
|
||||
values.split(',').forEach(v => {
|
||||
result.add(key, Buffer.from(v.trim(), 'base64'));
|
||||
});
|
||||
if (isCustomMetadata(key)) {
|
||||
values.split(',').forEach(v => {
|
||||
result.add(key, Buffer.from(v.trim(), 'base64'));
|
||||
});
|
||||
} else {
|
||||
result.add(key, Buffer.from(values, 'base64'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Array.isArray(values)) {
|
||||
|
@ -270,7 +278,11 @@ export class Metadata {
|
|||
result.add(key, value);
|
||||
});
|
||||
} else if (values !== undefined) {
|
||||
values.split(',').forEach(v => result.add(key, v.trim()));
|
||||
if (isCustomMetadata(key)) {
|
||||
values.split(',').forEach(v => result.add(key, v.trim()));
|
||||
} else {
|
||||
result.add(key, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -699,6 +699,18 @@ describe('Other conditions', () => {
|
|||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('for an error message with a comma', done => {
|
||||
client.unary(
|
||||
{ error: true, message: 'an error message, with a comma' },
|
||||
(err: ServiceError, data: any) => {
|
||||
assert(err);
|
||||
assert.strictEqual(err.code, grpc.status.UNKNOWN);
|
||||
assert.strictEqual(err.details, 'an error message, with a comma');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -553,6 +553,14 @@ describe(`${anyGrpc.clientName} client -> ${anyGrpc.serverName} server`, functio
|
|||
done();
|
||||
});
|
||||
});
|
||||
it('for an error message with a comma', function(done) {
|
||||
client.unary({error: true, message: 'a message, with a comma'}, function(err, data) {
|
||||
assert(err);
|
||||
assert.strictEqual(err.code, clientGrpc.status.UNKNOWN);
|
||||
assert.strictEqual(err.details, 'a message, with a comma');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue