Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2798,7 +2798,7 @@ function fromQueryString(search) {
const entries = search.split('&').map((i) => i.split('='));
const data = {};
entries.forEach(([key, value]) => {
value = decodeURIComponent(value.replace(/\+/g, '%20'));
value = decodeURIComponent(String(value || '').replace(/\+/g, '%20'));
if (!key.includes('[')) {
data[key] = value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/LiveComponent/assets/src/url_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function fromQueryString(search: string) {
const data: any = {};

entries.forEach(([key, value]) => {
value = decodeURIComponent(value.replace(/\+/g, '%20'));
value = decodeURIComponent(String(value || '').replace(/\+/g, '%20'));

if (!key.includes('[')) {
data[key] = value;
Expand Down
26 changes: 26 additions & 0 deletions src/LiveComponent/assets/test/url_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@ describe('url_utils', () => {
expect(urlUtils.search).toEqual('');
});
});

describe('fromQueryString', () => {
const urlUtils: UrlUtils = new UrlUtils(window.location.href);

beforeEach(() => {
// Reset search before each test
urlUtils.search = '';
});

it('parses a query string with value', () => {
urlUtils.search = '?param1=value1';
expect(urlUtils.get('param1')).toEqual('value1');
});

it('parses a query string with empty value', () => {
urlUtils.search = '?param1=&param2=value2';
expect(urlUtils.get('param1')).toEqual('');
expect(urlUtils.get('param2')).toEqual('value2');
});

it('parses a query string without equal sign', () => {
urlUtils.search = '?param1&param2=value2';
expect(urlUtils.get('param1')).toEqual('');
expect(urlUtils.get('param2')).toEqual('value2');
});
});
});

describe('HistoryStrategy', () => {
Expand Down