Skip to content

Commit b2b4104

Browse files
EFRS-1316: Changed a special characters regex to a new one
1 parent df93a43 commit b2b4104

File tree

10 files changed

+21
-20
lines changed

10 files changed

+21
-20
lines changed

java/admin/src/main/java/com/exadel/frs/dto/ui/AppCreateDto.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.exadel.frs.dto.ui;
1818

19-
import static com.exadel.frs.commonservice.system.global.RegExConstants.DOES_NOT_CONTAIN_SPECIAL_CHARACTERS;
19+
import static com.exadel.frs.commonservice.system.global.RegExConstants.ALLOWED_SPECIAL_CHARACTERS;
2020
import javax.validation.constraints.NotBlank;
2121
import javax.validation.constraints.Pattern;
2222
import javax.validation.constraints.Size;
@@ -33,6 +33,6 @@ public class AppCreateDto {
3333

3434
@NotBlank(message = "Application name cannot be empty")
3535
@Size(min = 1, max = 50, message = "Application name size must be between 1 and 50")
36-
@Pattern(regexp = DOES_NOT_CONTAIN_SPECIAL_CHARACTERS, message = "Only the following special characters are allowed: [].-_")
36+
@Pattern(regexp = ALLOWED_SPECIAL_CHARACTERS, message = "The name cannot contain the following special characters: ';', '/', '\\'")
3737
private String name;
3838
}

java/admin/src/main/java/com/exadel/frs/dto/ui/AppUpdateDto.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.exadel.frs.dto.ui;
1818

19-
import static com.exadel.frs.commonservice.system.global.RegExConstants.DOES_NOT_CONTAIN_SPECIAL_CHARACTERS;
19+
import static com.exadel.frs.commonservice.system.global.RegExConstants.ALLOWED_SPECIAL_CHARACTERS;
2020
import javax.validation.constraints.NotBlank;
2121
import javax.validation.constraints.Pattern;
2222
import javax.validation.constraints.Size;
@@ -33,6 +33,6 @@ public class AppUpdateDto {
3333

3434
@NotBlank(message = "Application name cannot be empty")
3535
@Size(min = 1, max = 50, message = "Application name size must be between 1 and 50")
36-
@Pattern(regexp = DOES_NOT_CONTAIN_SPECIAL_CHARACTERS, message = "Only the following special characters are allowed: [].-_")
36+
@Pattern(regexp = ALLOWED_SPECIAL_CHARACTERS, message = "The name cannot contain the following special characters: ';', '/', '\\'")
3737
private String name;
3838
}

java/admin/src/main/java/com/exadel/frs/dto/ui/ModelCloneDto.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.exadel.frs.dto.ui;
1818

19-
import static com.exadel.frs.commonservice.system.global.RegExConstants.DOES_NOT_CONTAIN_SPECIAL_CHARACTERS;
19+
import static com.exadel.frs.commonservice.system.global.RegExConstants.ALLOWED_SPECIAL_CHARACTERS;
2020
import javax.validation.constraints.NotBlank;
2121
import javax.validation.constraints.Pattern;
2222
import javax.validation.constraints.Size;
@@ -33,6 +33,6 @@ public class ModelCloneDto {
3333

3434
@NotBlank(message = "Model name cannot be empty")
3535
@Size(min = 1, max = 50, message = "Model name size must be between 1 and 50")
36-
@Pattern(regexp = DOES_NOT_CONTAIN_SPECIAL_CHARACTERS, message = "Only the following special characters are allowed: [].-_")
36+
@Pattern(regexp = ALLOWED_SPECIAL_CHARACTERS, message = "The name cannot contain the following special characters: ';', '/', '\\'")
3737
private String name;
3838
}

java/admin/src/main/java/com/exadel/frs/dto/ui/ModelCreateDto.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.exadel.frs.dto.ui;
1818

19-
import static com.exadel.frs.commonservice.system.global.RegExConstants.DOES_NOT_CONTAIN_SPECIAL_CHARACTERS;
19+
import static com.exadel.frs.commonservice.system.global.RegExConstants.ALLOWED_SPECIAL_CHARACTERS;
2020
import com.exadel.frs.commonservice.enums.ModelType;
2121
import com.exadel.frs.validation.ValidEnum;
2222
import javax.validation.constraints.NotBlank;
@@ -35,7 +35,7 @@ public class ModelCreateDto {
3535

3636
@NotBlank(message = "Model name cannot be empty")
3737
@Size(min = 1, max = 50, message = "Model name size must be between 1 and 50")
38-
@Pattern(regexp = DOES_NOT_CONTAIN_SPECIAL_CHARACTERS, message = "Only the following special characters are allowed: [].-_")
38+
@Pattern(regexp = ALLOWED_SPECIAL_CHARACTERS, message = "The name cannot contain the following special characters: ';', '/', '\\'")
3939
private String name;
4040

4141
@NotBlank(message = "Model Type cannot be empty")

java/admin/src/main/java/com/exadel/frs/dto/ui/ModelUpdateDto.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.exadel.frs.dto.ui;
1818

19-
import static com.exadel.frs.commonservice.system.global.RegExConstants.DOES_NOT_CONTAIN_SPECIAL_CHARACTERS;
19+
import static com.exadel.frs.commonservice.system.global.RegExConstants.ALLOWED_SPECIAL_CHARACTERS;
2020
import javax.validation.constraints.NotBlank;
2121
import javax.validation.constraints.Pattern;
2222
import javax.validation.constraints.Size;
@@ -33,6 +33,6 @@ public class ModelUpdateDto {
3333

3434
@NotBlank(message = "Model name cannot be empty")
3535
@Size(min = 1, max = 50, message = "Model name size must be between 1 and 50")
36-
@Pattern(regexp = DOES_NOT_CONTAIN_SPECIAL_CHARACTERS, message = "Only the following special characters are allowed: [].-_")
36+
@Pattern(regexp = ALLOWED_SPECIAL_CHARACTERS, message = "The name cannot contain the following special characters: ';', '/', '\\'")
3737
private String name;
3838
}

java/admin/src/test/java/com/exadel/frs/controller/AppControllerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public void shouldReturnOkWhenDeleteUserFromApp() throws Exception {
370370
public void shouldReturn400WhenTryingToSaveAppThatContainsSpecialCharactersWithinName() {
371371
var app = App.builder()
372372
.id(APP_ID)
373-
.name("+(new@app)+!")
373+
.name("\\new;app//")
374374
.build();
375375

376376
val request = post(ADMIN + "/app")
@@ -380,7 +380,7 @@ public void shouldReturn400WhenTryingToSaveAppThatContainsSpecialCharactersWithi
380380
.content(mapper.writeValueAsString(app)
381381
);
382382

383-
val expectedContent = "{\"message\":\"Only the following special characters are allowed: [].-_\",\"code\":36}";
383+
val expectedContent = "{\"message\":\"The name cannot contain the following special characters: ';', '/', '\\\\'\",\"code\":36}";
384384

385385
mockMvc.perform(request)
386386
.andExpect(status().isBadRequest())

java/admin/src/test/java/com/exadel/frs/controller/ModelControllerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,15 @@ void shouldReturnOkWhenDeleteModel() throws Exception {
259259
@SneakyThrows
260260
void shouldReturnErrorMessageWhenNameContainsSpecialCharactersOnCreateNewModel() {
261261
val bodyWithEmptyName = new ModelCreateDto();
262-
bodyWithEmptyName.setName("(model!)");
262+
bodyWithEmptyName.setName("\\new;model//");
263263
bodyWithEmptyName.setType("RECOGNITION");
264264

265265
mockMvc.perform(post(ADMIN + "/app/" + APP_GUID + "/model")
266266
.with(csrf())
267267
.with(user(buildUser()))
268268
.contentType(APPLICATION_JSON).content(mapper.writeValueAsString(bodyWithEmptyName)))
269269
.andExpect(status().isBadRequest())
270-
.andExpect(content().string("{\"message\":\"Only the following special characters are allowed: [].-_\",\"code\":36}"));
270+
.andExpect(content().string("{\"message\":\"The name cannot contain the following special characters: ';', '/', '\\\\'\"," +
271+
"\"code\":36}"));
271272
}
272273
}

java/api/src/main/java/com/exadel/frs/core/trainservice/dto/SubjectDto.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.exadel.frs.core.trainservice.dto;
22

3-
import static com.exadel.frs.commonservice.system.global.RegExConstants.DOES_NOT_CONTAIN_SPECIAL_CHARACTERS;
3+
import static com.exadel.frs.commonservice.system.global.RegExConstants.ALLOWED_SPECIAL_CHARACTERS;
44
import static com.exadel.frs.core.trainservice.system.global.Constants.SUBJECT_DESC;
55
import com.fasterxml.jackson.annotation.JsonProperty;
66
import io.swagger.annotations.ApiParam;
@@ -20,6 +20,6 @@ public class SubjectDto {
2020
@JsonProperty("subject")
2121
@NotBlank(message = "Subject name cannot be empty")
2222
@Size(min = 1, max = 50, message = "Subject name size must be between 1 and 50")
23-
@Pattern(regexp = DOES_NOT_CONTAIN_SPECIAL_CHARACTERS, message = "Only the following special characters are allowed: [].-_")
23+
@Pattern(regexp = ALLOWED_SPECIAL_CHARACTERS, message = "The name cannot contain the following special characters: ';', '/', '\\'")
2424
private String subjectName;
2525
}

java/common/src/main/java/com/exadel/frs/commonservice/system/global/RegExConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
@UtilityClass
66
public class RegExConstants {
77

8-
public static final String CONTAINS_SPECIAL_CHARACTERS = "[`~!@\"#№$%^:;&?<>(){|},/\\\\*+=]+";
9-
public static final String DOES_NOT_CONTAIN_SPECIAL_CHARACTERS = "[^`~!@\"#№$%^:;&?<>(){|},/\\\\*+=]+";
8+
public static final String ALLOWED_SPECIAL_CHARACTERS = "[^;/\\\\]+";
9+
public static final String PROHIBITED_SPECIAL_CHARACTERS = "[;/\\\\]+";
1010
}

java/common/src/main/java/com/exadel/frs/commonservice/system/liquibase/customchange/RemoveSpecialCharactersCustomChange.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.exadel.frs.commonservice.system.liquibase.customchange;
22

3-
import static com.exadel.frs.commonservice.system.global.RegExConstants.CONTAINS_SPECIAL_CHARACTERS;
3+
import static com.exadel.frs.commonservice.system.global.RegExConstants.PROHIBITED_SPECIAL_CHARACTERS;
44
import java.sql.PreparedStatement;
55
import java.sql.ResultSet;
66
import java.sql.SQLException;
@@ -32,7 +32,7 @@
3232
@Setter
3333
public class RemoveSpecialCharactersCustomChange implements CustomTaskChange {
3434

35-
private static final Pattern SPECIAL_CHARACTERS_PATTERN = Pattern.compile(CONTAINS_SPECIAL_CHARACTERS);
35+
private static final Pattern SPECIAL_CHARACTERS_PATTERN = Pattern.compile(PROHIBITED_SPECIAL_CHARACTERS);
3636

3737
private static final String COUNT_SQL_TEMPLATE = "SELECT COUNT(*) FROM ${table}";
3838
private static final String SELECT_SQL_TEMPLATE = "SELECT ${primaryKey}, ${target} FROM ${table}";

0 commit comments

Comments
 (0)