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

Added and improved user input validation for LSPTemplateUI #7893

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shivam71
Copy link
Contributor

  • Project,Package and Object names checked to be valid identifiers . Giving LSP client error messages for funky names like "123Funky$ Name"
  • Project and Object placement directories checked for write permission.

@Achal1607 Achal1607 added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) LSP [ci] enable Language Server Protocol tests VSCode Extension [ci] enable VSCode Extension tests labels Oct 22, 2024
@apache apache locked and limited conversation to collaborators Oct 22, 2024
@apache apache unlocked this conversation Oct 22, 2024
@shivam71
Copy link
Contributor Author

@lahodaj Please review my changes .


@Override
public CompletionStage<String> apply(String packageName) {
if (!SourceVersion.isName(packageName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we are specifically looking for a package name, so the check makes sense to me.

@@ -215,12 +238,14 @@ public CompletionStage<Pair<DataFolder,String>> apply(String path) {
}
targetPath.getParentFile().mkdirs();
FileObject fo = FileUtil.toFileObject(targetPath.getParentFile());
if (fo == null || !fo.isFolder()) {
if (fo == null || !fo.isFolder() || !targetPath.getParentFile().canWrite() || !SourceVersion.isName(targetPath.getName())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quite sure I read the patch correctly, but this is the folder where the project will be created. And the name of this folder does not necessarily need to follow the Java name rules(?). I mean, I can have a Java project in a directory called my-current-java-project, and there's no problem in that? Or do I miss something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right it will be the name of the folder where the project will be created . We need the java name rules because that is also used for the name of the main class . So if the path is /Users/Projects/my-current-java-project it will try to create a project with the main class name as my-current-java-project.


@Override
public CompletionStage<String> apply(String name) {
if (!SourceVersion.isName(name)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be OK for Java templates, but probably not for others (like plain files, XML/HTML files, etc.) And this will be used for all file types, I think. I don't know offhand how to do validation only for Java, it might need another attribute on the template(?). @sdedic? Do I miss something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know offhand how to do validation only for Java, it might need another attribute on the template(?). @sdedic? Do I miss something?

I think a validator could specified by a template's file attribute, or by template's MIME type (for singe-file templates).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lahodaj Thanks for pointing that out ! I looked up a bit more on this , it seems that all java templates have names ending with ".java" suffix , Can you confirm that ? If thats the case then I can condition on the template name whether to apply the validation check or not .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR with conditional validation using MIME type .

- Validations for package name, object name and folder paths
@shivam71 shivam71 force-pushed the LSPTemplateUI_UserInputValidation branch from 1dd8d80 to 8e94890 Compare November 20, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) LSP [ci] enable Language Server Protocol tests VSCode Extension [ci] enable VSCode Extension tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants