From ba9c12f2e0311ab8176cfe331b0d320e2cd69156 Mon Sep 17 00:00:00 2001 From: BastiOfBerlin Date: Mon, 11 Feb 2019 17:17:04 +0100 Subject: [PATCH] Don't escape [ and ] in query param keys (#2107) rails' default naming for arrays is name[]=...&name[]=... It doesn't recognize the escaped forms %5B + %5D but fails silently --- .../main/resources/typescript-angular/encoder.mustache | 8 ++++++-- .../petstore/typescript-angular-v2/default/encoder.ts | 4 +++- .../typescript-angular-v2/with-interfaces/encoder.ts | 4 +++- .../petstore/typescript-angular-v4.3/npm/encoder.ts | 4 +++- .../client/petstore/typescript-angular-v4/npm/encoder.ts | 4 +++- .../builds/default/encoder.ts | 4 +++- .../builds/with-npm/encoder.ts | 4 +++- .../builds/default/encoder.ts | 4 +++- .../builds/with-npm/encoder.ts | 4 +++- .../builds/default/encoder.ts | 4 +++- .../builds/with-npm/encoder.ts | 4 +++- .../builds/default/encoder.ts | 4 +++- .../builds/with-npm/encoder.ts | 4 +++- 13 files changed, 42 insertions(+), 14 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/encoder.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/encoder.mustache index c3ac784124a2..cdecfdd44497 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/encoder.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/encoder.mustache @@ -14,7 +14,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); @@ -31,7 +33,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { export class CustomQueryEncoderHelper extends QueryEncoder { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v2/default/encoder.ts b/samples/client/petstore/typescript-angular-v2/default/encoder.ts index 6fcda7b246dd..71f99f9c7041 100644 --- a/samples/client/petstore/typescript-angular-v2/default/encoder.ts +++ b/samples/client/petstore/typescript-angular-v2/default/encoder.ts @@ -8,7 +8,9 @@ export class CustomQueryEncoderHelper extends QueryEncoder { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/encoder.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/encoder.ts index 6fcda7b246dd..71f99f9c7041 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/encoder.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/encoder.ts @@ -8,7 +8,9 @@ export class CustomQueryEncoderHelper extends QueryEncoder { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts b/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts index f1c6b78c9c8e..7f1ef7c4f2a3 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts @@ -8,7 +8,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v4/npm/encoder.ts b/samples/client/petstore/typescript-angular-v4/npm/encoder.ts index 6fcda7b246dd..71f99f9c7041 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/encoder.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/encoder.ts @@ -8,7 +8,9 @@ export class CustomQueryEncoderHelper extends QueryEncoder { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/encoder.ts b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/encoder.ts index f1c6b78c9c8e..7f1ef7c4f2a3 100644 --- a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/encoder.ts +++ b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/encoder.ts @@ -8,7 +8,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/encoder.ts b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/encoder.ts index f1c6b78c9c8e..7f1ef7c4f2a3 100644 --- a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/encoder.ts +++ b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/encoder.ts @@ -8,7 +8,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/encoder.ts b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/encoder.ts index f1c6b78c9c8e..7f1ef7c4f2a3 100644 --- a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/encoder.ts +++ b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/encoder.ts @@ -8,7 +8,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/encoder.ts b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/encoder.ts index f1c6b78c9c8e..7f1ef7c4f2a3 100644 --- a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/encoder.ts +++ b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/encoder.ts @@ -8,7 +8,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default/encoder.ts b/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default/encoder.ts index f1c6b78c9c8e..7f1ef7c4f2a3 100644 --- a/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default/encoder.ts +++ b/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default/encoder.ts @@ -8,7 +8,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm/encoder.ts b/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm/encoder.ts index f1c6b78c9c8e..7f1ef7c4f2a3 100644 --- a/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm/encoder.ts +++ b/samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm/encoder.ts @@ -8,7 +8,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default/encoder.ts b/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default/encoder.ts index f1c6b78c9c8e..7f1ef7c4f2a3 100644 --- a/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default/encoder.ts +++ b/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/default/encoder.ts @@ -8,7 +8,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v); diff --git a/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm/encoder.ts b/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm/encoder.ts index f1c6b78c9c8e..7f1ef7c4f2a3 100644 --- a/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm/encoder.ts +++ b/samples/client/petstore/typescript-angular-v7-provided-in-root/builds/with-npm/encoder.ts @@ -8,7 +8,9 @@ export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); - return k.replace(/\+/gi, '%2B'); + return k.replace(/\+/gi, '%2B') + .replace(/%5B/, "[").replace(/%5D/, "]") + ; } encodeValue(v: string): string { v = super.encodeValue(v);