Fix: special character only chat messages #336
@@ -247,8 +247,7 @@ public class ClientService {
|
|||||||
// Allow primitive values to contain hyphens (UUIDs) in addition to
|
// Allow primitive values to contain hyphens (UUIDs) in addition to
|
||||||
// digits/words/colons
|
// digits/words/colons
|
||||||
static Pattern responseRex =
|
static Pattern responseRex =
|
||||||
Pattern.compile(
|
Pattern.compile("(?<key>\\w+)=(('(?<string>([^']|\\')+)')|(?<primVal>[^ ]+))");
|
||||||
"(?<key>\\w+)=(('(?<string>([^']|\\')+)')|(?<primVal>[+-]?[-\\d\\w:]+))");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes escape characters from a string, specifically converting escaped single quotes (\')
|
* Removes escape characters from a string, specifically converting escaped single quotes (\')
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ public class ChatViewController implements Initializable {
|
|||||||
public void sendMessage() {
|
public void sendMessage() {
|
||||||
SoundManager.getInstance().playButtonClick();
|
SoundManager.getInstance().playButtonClick();
|
||||||
String message = inputField.getText().trim();
|
String message = inputField.getText().trim();
|
||||||
|
|
||||||
|
message = message.replace("'", " ");
|
||||||
|
|
||||||
if (!message.isEmpty()) {
|
if (!message.isEmpty()) {
|
||||||
inputField.clear();
|
inputField.clear();
|
||||||
String currentUsername = controller.getCurrentUsername();
|
String currentUsername = controller.getCurrentUsername();
|
||||||
|
|||||||
@@ -16,9 +16,9 @@
|
|||||||
<HBox spacing="10"
|
<HBox spacing="10"
|
||||||
fx:id="menuBox">
|
fx:id="menuBox">
|
||||||
|
|
||||||
<Label text="== CHAT ==" styleClass="chat-header" alignment="CENTER" maxWidth="Infinity"/>
|
<Label text="CHAT" styleClass="chat-header" alignment="CENTER" maxWidth="Infinity"/>
|
||||||
<Region HBox.hgrow="ALWAYS"/>
|
<Region HBox.hgrow="ALWAYS"/>
|
||||||
<MenuButton fx:id="addWhisperChatButton" styleClass="menu-button" text="WHISPER CHAT"
|
<MenuButton fx:id="addWhisperChatButton" styleClass="menu-button" text="WHISPER"
|
||||||
alignment="CENTER_RIGHT">
|
alignment="CENTER_RIGHT">
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
</HBox>
|
</HBox>
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package ch.unibas.dmi.dbis.cs108.casono.client.network;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.RequestParameter;
|
||||||
|
import java.util.*;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class ClientServiceTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parsingResponse() {
|
||||||
|
ArrayList<RequestParameter> params = new ArrayList<>();
|
||||||
|
|
||||||
|
params.add(new RequestParameter("KEY", "VALUE"));
|
||||||
|
params.add(
|
||||||
|
new RequestParameter(
|
||||||
|
"STANDARD_TEXT",
|
||||||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit"));
|
||||||
|
params.add(new RequestParameter("TEXT_BASED_EMOJI_WITHOUT_QUOTATION_MARKS", ";-)"));
|
||||||
|
params.add(
|
||||||
|
new RequestParameter("TEXT_WITH_QUOTATION_MARKS", "SOMEBODY SAYS: 'HALLO WELT'"));
|
||||||
|
params.add(new RequestParameter("NUMBERS", "123456789"));
|
||||||
|
params.add(new RequestParameter("SOME_SPECIAL_CHARACTERS", "°^!§$%&/()=[]}?*+~'#`"));
|
||||||
|
params.add(new RequestParameter("WRONG_CHARACTERS", "# * ~ +"));
|
||||||
|
params.add(new RequestParameter("WRONG_TEXT", "HELLO WORLD"));
|
||||||
|
|
||||||
|
ArrayList<String> paramsAsResponseLines = new ArrayList<>();
|
||||||
|
|
||||||
|
for (RequestParameter parameter : params) {
|
||||||
|
if (!parameter.key().equals("WRONG_TEXT")
|
||||||
|
&& !parameter.key().equals("WRONG_CHARACTERS")
|
||||||
|
&& parameter.value().contains(" ")) {
|
||||||
|
String newValue = "'" + parameter.value() + "'";
|
||||||
|
paramsAsResponseLines.add(String.format("%s=%s", parameter.key(), newValue));
|
||||||
|
} else {
|
||||||
|
paramsAsResponseLines.add(
|
||||||
|
String.format("%s=%s", parameter.key(), parameter.value()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(8, paramsAsResponseLines.size());
|
||||||
|
|
||||||
|
List<RequestParameter> msgRes =
|
||||||
|
new ArrayList<>(ClientService.convertToRequestParameters(paramsAsResponseLines));
|
||||||
|
|
||||||
|
assertEquals(6, msgRes.size());
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
assertEquals(params.get(i), msgRes.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
assert (!msgRes.contains(params.get(6)));
|
||||||
|
assert (!msgRes.contains(params.get(7)));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user