diff --git a/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java b/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java index 642553e..53853b8 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java +++ b/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java @@ -17,6 +17,7 @@ import java.util.regex.Pattern; */ public class TypeAssumptionParser { + private static final Pattern TYPE_NAME_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9]*"); private static final Pattern TYPE_VARIABLE_PATTERN = Pattern.compile("t(\\d+)"); /** @@ -28,7 +29,11 @@ public class TypeAssumptionParser { public Result, ParseError> parse(Map assumptions) { Map typeAssumptions = new LinkedHashMap<>(); for (Map.Entry entry : assumptions.entrySet()) { - VarTerm var = new VarTerm(entry.getKey()); + String typeName = entry.getKey(); + if (!TYPE_NAME_PATTERN.matcher(typeName).matches()) { + return new Result<>(null, ParseError.UNEXPECTED_CHARACTER); + } + VarTerm var = new VarTerm(typeName); Result typeAbs = parseType(entry.getValue()); if (typeAbs.isError()) { return new Result<>(typeAbs); diff --git a/src/main/java/edu/kit/typicalc/util/package-info.java b/src/main/java/edu/kit/typicalc/util/package-info.java index c87488b..1fab186 100644 --- a/src/main/java/edu/kit/typicalc/util/package-info.java +++ b/src/main/java/edu/kit/typicalc/util/package-info.java @@ -1,9 +1,4 @@ /** * The util package contains classes used in all components of the application. */ -@NonNullFields -@NonNullApi -package edu.kit.typicalc.util; - -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; \ No newline at end of file +package edu.kit.typicalc.util; \ No newline at end of file diff --git a/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java b/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java index 748e782..286f45a 100644 --- a/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java +++ b/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java @@ -209,6 +209,14 @@ class TypeAssumptionParserTest { assertTrue(type.isError()); assertEquals(entry.getValue(), type.unwrapError()); } + TypeAssumptionParser parser = new TypeAssumptionParser(); + Result, ParseError> type = parser.parse(Map.of("föhn", "int")); + assertTrue(type.isError()); + assertEquals(ParseError.UNEXPECTED_CHARACTER, type.unwrapError()); + parser = new TypeAssumptionParser(); + type = parser.parse(Map.of("1typ", "int")); + assertTrue(type.isError()); + assertEquals(ParseError.UNEXPECTED_CHARACTER, type.unwrapError()); } @Test