Skip to content

Commit fd6e2c8

Browse files
sanitize the case urn
1 parent d6818b7 commit fd6e2c8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ dependencies {
226226

227227
implementation group: 'io.rest-assured', name: 'rest-assured', version: '5.5.5'
228228
implementation 'org.hibernate.validator:hibernate-validator:9.0.0.Final'
229-
implementation 'org.apache.commons:commons-lang3:3.17.0'
229+
implementation 'org.apache.commons:commons-text:1.13.1'
230230

231231
compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
232232
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion

src/main/java/uk/gov/hmcts/cp/controllers/CourtScheduleController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package uk.gov.hmcts.cp.controllers;
22

3+
import org.apache.commons.text.StringEscapeUtils;
34
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
56
import org.springframework.http.HttpStatus;
@@ -21,15 +22,21 @@ public CourtScheduleController(CourtScheduleService courtScheduleService) {
2122

2223
@Override
2324
public ResponseEntity<CourtScheduleResponse> getCourtScheduleByCaseUrn(String caseUrn) {
25+
String sanitizedCaseUrn;
2426
CourtScheduleResponse courtScheduleResponse;
2527
try {
26-
courtScheduleResponse = courtScheduleService.getCourtScheduleResponse(caseUrn);
28+
sanitizedCaseUrn = sanitizeCaseUrn(caseUrn);
29+
courtScheduleResponse = courtScheduleService.getCourtScheduleResponse(sanitizedCaseUrn);
2730
} catch (ResponseStatusException e) {
2831
log.error(e.getMessage());
2932
return ResponseEntity.status(e.getStatusCode()).build();
3033
}
31-
log.debug("getCourtScheduleByCaseUrn: {}", caseUrn);
34+
log.debug("Found court schedule for caseUrn: {}", sanitizedCaseUrn);
3235
return new ResponseEntity<>(courtScheduleResponse, HttpStatus.OK);
3336
}
3437

38+
private String sanitizeCaseUrn(String urn) {
39+
if (urn == null) throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "caseUrn is required");;
40+
return StringEscapeUtils.escapeHtml4(urn);
41+
}
3542
}

0 commit comments

Comments
 (0)