Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qute - improve validation of param declarations #21947

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,12 @@ private void flushTag() {
// Parameter declaration
// {@org.acme.Foo foo}
Scope currentScope = scopeStack.peek();
int spaceIdx = content.indexOf(" ");
String key = content.substring(spaceIdx + 1, content.length());
String value = content.substring(1, spaceIdx);
String[] parts = content.substring(1).trim().split("[ ]{1,}");
if (parts.length != 2) {
throw parserError("invalid parameter declaration " + START_DELIMITER + buffer.toString() + END_DELIMITER);
}
String value = parts[0];
String key = parts[1];
currentScope.putBinding(key, Expressions.typeInfoFrom(value));
sectionStack.peek().currentBlock().addNode(new ParameterDeclarationNode(content, origin(0)));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,20 @@ public void testInvalidBracket() {
"Parser error on line 1: invalid bracket notation expression in {foo.baz[}", 1);
}

@Test
public void testInvalidParamDeclaration() {
assertParserError("{@com.foo }",
"Parser error on line 1: invalid parameter declaration {@com.foo }", 1);
assertParserError("{@ com.foo }",
"Parser error on line 1: invalid parameter declaration {@ com.foo }", 1);
assertParserError("{@com.foo.Bar bar baz}",
"Parser error on line 1: invalid parameter declaration {@com.foo.Bar bar baz}", 1);
assertParserError("{@}",
"Parser error on line 1: invalid parameter declaration {@}", 1);
assertParserError("{@\n}",
"Parser error on line 1: invalid parameter declaration {@\n}", 1);
}

public static class Foo {

public List<Item> getItems() {
Expand Down