Skip to content

Commit 88de30b

Browse files
Merge pull request #1352 from geonetwork/backport/2.6.x/pr-1334
[2.6.x] Wrong slash and comma behaviour for organizations (#1334)
2 parents 8af4387 + 85034ae commit 88de30b

7 files changed

Lines changed: 53 additions & 6 deletions

File tree

apps/datahub/src/app/organization/organization-details/organization-details.component.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
<a
3636
data-test="organizationDatasetCount"
3737
[routerLink]="['/', ROUTER_ROUTE_SEARCH]"
38-
[queryParams]="{ organization: organization.name }"
38+
[queryParams]="{
39+
organization: sanitizeOrgName(organization.name),
40+
}"
3941
>
4042
<gn-ui-figure
4143
class="py-[37px] pl-[47px] rounded-lg border bg-white mb-5 card-shadow cursor-pointer"
@@ -78,7 +80,9 @@
7880
[records]="lastPublishedDatasets"
7981
[routerLinkButton]="{
8082
routerLink: ['/', ROUTER_ROUTE_SEARCH],
81-
queryParams: { organization: organization.name },
83+
queryParams: {
84+
organization: sanitizeOrgName(organization.name),
85+
},
8286
label:
8387
'organization.details.lastPublishedDatasets.searchAllButton'
8488
| translate,

apps/datahub/src/app/organization/organization-details/organization-details.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,8 @@ export class OrganizationDetailsComponent implements OnInit, OnDestroy {
118118
}
119119

120120
protected readonly errorTypes = ErrorType
121+
122+
sanitizeOrgName(name: string): string {
123+
return name ? name.replace(/,/g, '%2C') : name
124+
}
121125
}

apps/datahub/src/app/organization/organization-page/organization-page.component.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,24 @@ describe('OrganizationPageComponent', () => {
8282
expect(org).toEqual(orgWithSlash)
8383
})
8484
})
85+
86+
it('should match orgs with multiple slash', () => {
87+
const orgWithSlash = {
88+
...expectedOrganization,
89+
name: 'org/with/multiples/slash',
90+
}
91+
92+
const orgService = TestBed.inject(OrganizationsServiceInterface) as any
93+
orgService.organisations$ = of([orgWithSlash])
94+
95+
const router = TestBed.inject(RouterFacade) as any
96+
router.pathParams$ = of({ name: 'orgwithmultiplesslash' })
97+
98+
component.ngOnInit()
99+
100+
component.organization$.subscribe((org) => {
101+
expect(org).toEqual(orgWithSlash)
102+
})
103+
})
85104
})
86105
})

apps/datahub/src/app/organization/organization-page/organization-page.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class OrganizationPageComponent implements OnInit {
4141
switchMap(([pathParams, organizations]) => {
4242
const organization = organizations.find(
4343
(organization) =>
44-
organization.name.replace('/', '') === pathParams['name']
44+
organization.name.replaceAll('/', '') === pathParams['name']
4545
)
4646
return of(organization)
4747
})

libs/feature/router/src/lib/default/state/query-params.utils.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ describe('query params utilities', () => {
2424
emptyParam: [],
2525
})
2626
})
27+
28+
it('correctly encodes organization names with commas', () => {
29+
const params = flattenQueryParams({
30+
organization: ['Société, Inc., Main Branch', 'Other Org'],
31+
})
32+
expect(params).toEqual({
33+
organization: ['Société%2C Inc.%2C Main Branch,Other Org'],
34+
})
35+
})
2736
})
2837
describe('expandQueryParams', () => {
2938
it('restores full route parameters from serialized query params in arrays', () => {
@@ -55,5 +64,13 @@ describe('query params utilities', () => {
5564
},
5665
})
5766
})
67+
it('correctly handles organization names with commas', () => {
68+
const params = expandQueryParams({
69+
organization: ['Société%2C Inc.%2C Main Branch,Other Org'],
70+
})
71+
expect(params).toEqual({
72+
organization: ['Société, Inc., Main Branch', 'Other Org'],
73+
})
74+
})
5875
})
5976
})

libs/feature/router/src/lib/default/state/query-params.utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export function flattenQueryParams(
1414
Array.isArray(flattened[key]) &&
1515
(flattened[key] as string[]).length > 0
1616
) {
17-
flattened[key] = [(flattened[key] as string[]).join(',')]
17+
const encoded = (flattened[key] as string[]).map((value) =>
18+
typeof value === 'string' ? value.replace(/,/g, '%2C') : value
19+
)
20+
flattened[key] = [encoded.join(',')]
1821
} else if (isDateRange(flattened[key] as DateRange)) {
1922
const start = (flattened[key] as DateRange).start
2023
const end = (flattened[key] as DateRange).end
@@ -48,7 +51,7 @@ export function expandQueryParams(
4851
...(end && { end: new Date(`${end}T00:00:00`) }),
4952
}
5053
} else {
51-
expanded[key] = value.split(',')
54+
expanded[key] = value.split(',').map((v) => v.replace(/%2C/g, ','))
5255
}
5356
}
5457
}

libs/feature/router/src/lib/default/state/router.facade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class RouterFacade {
6363
}
6464

6565
goToOrganization(organizationName: string) {
66-
const safeOrgName = organizationName.replace('/', '')
66+
const safeOrgName = organizationName.replace(/\//g, '')
6767
const path = `${this.routerService.getOrganizationPageRoute()}/${safeOrgName}`
6868
this.go({
6969
path,

0 commit comments

Comments
 (0)