Skip to content

Commit ac951eb

Browse files
author
Ritesh Shukla
committed
Fixed Issue with Bulk Message
1 parent 40f277c commit ac951eb

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

packages/react-native/Libraries/Blob/URLSearchParams.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export class URLSearchParams {
1414
_searchParams: Map<string, string[]> = new Map();
1515

1616
constructor(params?: Record<string, string> | string | [string, string][]) {
17+
18+
if(params === null){
19+
return;
20+
}
21+
1722
// URLSearchParams("key1=value1&key2=value2");
1823
if (typeof params === 'string') {
1924
params
@@ -23,7 +28,7 @@ export class URLSearchParams {
2328
if (!pair) {
2429
return;
2530
}
26-
const [key, value] = pair.split('=').map(decodeURIComponent);
31+
const [key, value] = pair.split('=').map(part => decodeURIComponent(part.replace(/\+/g, ' ')));
2732
this.append(key, value);
2833
});
2934
}
@@ -67,11 +72,11 @@ export class URLSearchParams {
6772
this._searchParams.set(name, [value]);
6873
}
6974

70-
keys(name: string): Iterator<string> {
75+
keys(): Iterator<string> {
7176
return this._searchParams.keys();
7277
}
7378

74-
values(name: string): Iterator<string> {
79+
values(): Iterator<string> {
7580
function* generateValues(params: Map<string, string[]>): Iterator<string> {
7681
for (const valueArray of params.values()) {
7782
for (const value of valueArray) {
@@ -82,7 +87,7 @@ export class URLSearchParams {
8287
return generateValues(this._searchParams);
8388
}
8489

85-
entries(name: string): Iterator<[string, string]> {
90+
entries(): Iterator<[string, string]> {
8691
function* generateEntries(
8792
params: Map<string, string[]>,
8893
): Iterator<[string, string]> {
@@ -126,14 +131,16 @@ export class URLSearchParams {
126131
}
127132

128133
toString(): string {
129-
return Array.from(this._searchParams.entries())
130-
.map(([key, values]) =>
131-
values
132-
.map(
133-
value => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`,
134-
)
135-
.join('&'),
136-
)
137-
.join('&');
138-
}
134+
return Array.from(this._searchParams.entries())
135+
.map(([key, values]) =>
136+
values
137+
.map(
138+
value =>
139+
`${encodeURIComponent(key).replace(/%20/g, '+')}=${encodeURIComponent(value)
140+
.replace(/%20/g, '+')}` // Convert only spaces to '+'
141+
)
142+
.join('&'),
143+
)
144+
.join('&');
145+
}
139146
}

packages/react-native/Libraries/Blob/__tests__/URL-test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ describe('URL', function () {
6161
expect(searchParams.get('key')).toBe('value');
6262

6363
const paramsFromString = new URLSearchParams(
64-
'?param1=value1&param2=value2',
64+
'?param1=value1+value2&param2=value%20with%20space',
6565
);
66-
expect(paramsFromString.get('param1')).toBe('value1');
67-
expect(paramsFromString.get('param2')).toBe('value2');
66+
67+
68+
expect(paramsFromString.get('param1')).toBe('value1 value2');
69+
expect(paramsFromString.get('param2')).toBe('value with space');
70+
expect(paramsFromString.toString()).toBe('param1=value1+value2&param2=value+with+space');
71+
72+
6873

6974
const paramsFromObject = new URLSearchParams({
7075
user: 'john',

0 commit comments

Comments
 (0)