Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit d927426

Browse files
BoykoAlexjvalkeal
authored andcommitted
Encoder of HTTP request parameters
Encoder of HTTP request parameters Encoder of HTTP request parameters
1 parent cbdeb09 commit d927426

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { URL_QUERY_ENCODER } from './http.utils';
2+
3+
describe('HTTP Utils', () => {
4+
5+
it('Encode + in key', () => {
6+
expect(URL_QUERY_ENCODER.encodeKey('2 + 2 = 4')).toEqual('2%20%2B%202%20=%204');
7+
});
8+
9+
it('Encode + in value', () => {
10+
expect(URL_QUERY_ENCODER.encodeValue('2 + 2 = 4')).toEqual('2%20%2B%202%20=%204');
11+
});
12+
13+
});

ui/src/app/shared/support/http.utils.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Headers, RequestOptions, URLSearchParams } from '@angular/http';
1+
import { Headers, RequestOptions, URLSearchParams, QueryEncoder } from '@angular/http';
22

33
/**
44
* Contains common HTTP-related helper methods.
@@ -25,3 +25,17 @@ export class HttpUtils {
2525
return params;
2626
}
2727
}
28+
29+
class UrlQueryEncoder extends QueryEncoder {
30+
31+
encodeKey(k: string): string {
32+
return super.encodeKey(k).replace(/\+/gi, '%2B');
33+
}
34+
35+
encodeValue(v: string): string {
36+
return super.encodeValue(v).replace(/\+/gi, '%2B');
37+
}
38+
39+
}
40+
41+
export const URL_QUERY_ENCODER = new UrlQueryEncoder();

ui/src/app/streams/streams.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'rxjs/add/operator/map';
88
import { StreamDefinition } from './model/stream-definition';
99
import { Page } from '../shared/model/page';
1010
import { ErrorHandler } from '../shared/model/error-handler';
11-
import { HttpUtils } from '../shared/support/http.utils';
11+
import { HttpUtils, URL_QUERY_ENCODER } from '../shared/support/http.utils';
1212

1313
/**
1414
* Provides {@link StreamDefinition} related services.
@@ -85,7 +85,7 @@ export class StreamsService {
8585
}
8686

8787
createDefinition(name: string, dsl: string, deploy?: boolean): Observable<Response> {
88-
const params = new URLSearchParams();
88+
const params = new URLSearchParams('', URL_QUERY_ENCODER);
8989
params.append('name', name);
9090
params.append('definition', dsl);
9191
if (deploy) {

0 commit comments

Comments
 (0)