Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-native/Libraries/Blob/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export class URL {
}

get hash(): string {
const hashMatch = this._url.match(/#([^/]*)/);
return hashMatch ? `#${hashMatch[1]}` : '';
const hashIndex = this._url.indexOf('#');
return hashIndex !== -1 ? this._url.slice(hashIndex) : '';
}

get host(): string {
Expand Down
14 changes: 10 additions & 4 deletions packages/react-native/Libraries/Blob/URLSearchParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export class URLSearchParams {
_searchParams: Map<string, string[]> = new Map();

get size(): number {
return this._searchParams.size;
let count = 0;
for (const values of this._searchParams.values()) {
count += values.length;
}
return count;
}

constructor(params?: Record<string, string> | string | [string, string][]) {
Expand All @@ -33,9 +37,11 @@ export class URLSearchParams {
if (!pair) {
return;
}
const [key, value] = pair
.split('=')
.map(part => decodeURIComponent(part.replace(/\+/g, ' ')));
const eqIndex = pair.indexOf('=');
const rawKey = eqIndex === -1 ? pair : pair.slice(0, eqIndex);
const rawValue = eqIndex === -1 ? '' : pair.slice(eqIndex + 1);
const key = decodeURIComponent(rawKey.replace(/\+/g, ' '));
const value = decodeURIComponent(rawValue.replace(/\+/g, ' '));
this.append(key, value);
});
} else if (Array.isArray(params)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Blob/__tests__/URL-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('URL', function () {
['key1', 'value2'],
['key2', 'value3'],
]);
expect(paramsFromArray.size).toBe(2);
expect(paramsFromArray.size).toBe(3);
expect(paramsFromArray.getAll('key1')).toEqual(['value1', 'value2']);
expect(paramsFromArray.get('key2')).toBe('value3');

Expand Down
Loading