diff --git a/core/packages/gax/src/transcoding.ts b/core/packages/gax/src/transcoding.ts index 37b399f50e2e..3f313d8dd65f 100644 --- a/core/packages/gax/src/transcoding.ts +++ b/core/packages/gax/src/transcoding.ts @@ -151,14 +151,16 @@ export function encodeWithSlashes(str: string): string { return str .split('') .map(c => (c.match(/[-_.~0-9a-zA-Z]/) ? c : encodeURIComponent(c))) - .join(''); + .join('') + .replace(/\.\./g, '%2E%2E'); } export function encodeWithoutSlashes(str: string): string { return str .split('') .map(c => (c.match(/[-_.~0-9a-zA-Z/]/) ? c : encodeURIComponent(c))) - .join(''); + .join('') + .replace(/\.\./g, '%2E%2E'); } function escapeRegExp(str: string) { diff --git a/core/packages/gax/test/unit/transcoding.ts b/core/packages/gax/test/unit/transcoding.ts index f6c6669c6bea..813c4bcc796a 100644 --- a/core/packages/gax/test/unit/transcoding.ts +++ b/core/packages/gax/test/unit/transcoding.ts @@ -368,6 +368,7 @@ describe('gRPC to HTTP transcoding', () => { ), '_.~0-9abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%2F%20', ); + assert.strictEqual(encodeWithSlashes('..'), '%2E%2E'); }); it('encodeWithoutSlashes', () => { @@ -382,6 +383,8 @@ describe('gRPC to HTTP transcoding', () => { ), '_.~0-9abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/%20', ); + assert.strictEqual(encodeWithoutSlashes('..'), '%2E%2E'); + assert.strictEqual(encodeWithoutSlashes('..?$httpMethod=DELETE#'), '%2E%2E%3F%24httpMethod%3DDELETE%23'); }); it('applyPattern', () => {