-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Milestone
Description
Description
As reported in angular/angular#11058, URLSearchParams does not allow to pass '+' character. Currently I am developing a search interface with email and email can contain '+' character obviously like foo+bar@example.com. So this behavior is problem for me.
Swagger-codegen version
Latest master
Suggest a fix/enhancement
URLSearchParams can receive customized encoder as in the document. My suggestion is implement custom encoder as follows:
/*
* CustomQueryEncoderHelper
* Fix plus sign (+) not encoding, so sent as blank space
* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318
*/
import { QueryEncoder } from "@angular/http";
export class CustomQueryEncoderHelper extends QueryEncoder {
encodeKey(k: string): string {
k = super.encodeKey(k);
return k.replace(/\+/gi, '%2B');
}
encodeValue(v: string): string {
v = super.encodeValue(v);
return v.replace(/\+/gi, '%2B');
}
}And update URLSearchParams in api.service.mustache as follows.
let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper());This code is cited from this comment in angular/angular#11058.
I will file a PR soon if there is no problem.
Simon-Briggs