Skip to content

Commit

Permalink
Don't escape [ and ] in query param keys (#2107)
Browse files Browse the repository at this point in the history
rails' default naming for arrays is name[]=...&name[]=...
It doesn't recognize the escaped forms %5B + %5D but fails silently
  • Loading branch information
BastiOfBerlin authored and wing328 committed Feb 11, 2019
1 parent 73d309b commit ba9c12f
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion samples/client/petstore/typescript-angular-v4/npm/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ba9c12f

Please sign in to comment.