Closed wojcraft closed 2 months ago
You are right, it is not possible to use '/' as input in the project name. If the go-blueprint create -n github.com/user/project-name command is executed, the CLI would create subdirectories after '/'. Thanks for addressing this....it needs to be fixed.
This is an easy fix, the only thing that needs to be changed is the regex in the sanitizeInput() function (textinput.go):
func sanitizeInput(input string) error {
matched, err := regexp.Match("^[a-zA-Z0-9_\\-\\./]+$", []byte(input))
if !matched {
return fmt.Errorf("string violates the input regex pattern, err: %v", err)
}
return nil
}
This is an easy fix, the only thing that needs to be changed is the regex in the sanitizeInput() function (textinput.go):
func sanitizeInput(input string) error { matched, err := regexp.Match("^[a-zA-Z0-9_\\-\\./]+$", []byte(input)) if !matched { return fmt.Errorf("string violates the input regex pattern, err: %v", err) } return nil }
/^[a-zA-Z0-9_\-\.\/]+$
I rather meant to make dots and slashes available at the same time. To allow urls like github.com/wojcraft/test
I embedded screenshot
I agree...I did just a quick test.
Wait, I think you don't have to explicitly use a regex because it's a string.
Dear @Ujstor,
So, are you going to implement this feature? I feel a little disoriented looking at this issue, so I'm just asking about a status of it.
If you want to know more details about what I mean in this quite small Feature Request, just let me know!
All the best! Wojcraft
The issue is open, and anyone can solve it and submit a PR :)
Hi @Ujstor
If the project name entered is "github.com/wojcraft/project-name", could you please suggest what should be the expected behavior from 1 or 2?
Behavior 1: root folder name: project-name module name: github.com/wojcraft/project-name
Behavior 2: root folder name: github.com/wojcraft/project-name module name: github.com/wojcraft/project-name
If behavior 2 is expected, than is it possible on Linux based operating systems to have / in directory name?
@Patel-Raj I think option number 1 would be best to implement because of cross-platform compatibility: root folder name: project-name module name: github.com/wojcraft/project-name
Behavior 2 is what you get if we change the sanitizeInput function and allow . and /. In this case, the blueprint’s default behavior will create a directory tree github.com/wojcraft/project-name. As you pointed out, on Windows, this will be a big issue.
@H0llyW00dzZ This is why regex is used, not just a plain string.
@Patel-Raj I think option number 1 would be best to implement because of cross-platform compatibility: root folder name: project-name module name: github.com/wojcraft/project-name
Behavior 2 is what you get if we change the sanitizeInput function and allow . and /. In this case, the blueprint’s default behavior will create a directory tree github.com/wojcraft/project-name. As you pointed out, on Windows, this will be a big issue.
@H0llyW00dzZ This is why regex is used, not just a plain string.
It can be more easily achieved using the URL builder from the standard library and removing the scheme (http/https) instead of using regex.
for example:
func sanitizeInput(input string) error {
// Remove the URL scheme (e.g., http://, https://) from the input
input = strings.TrimPrefix(strings.TrimPrefix(input, "https://"), "http://")
_, err := url.Parse("//" + input)
if err != nil {
return fmt.Errorf("invalid input: %v", err)
}
return nil
}
And then For non-URL cases, it can be achieved by using regex because if using regex for URIs/URLs
such as github.com/wojcraft/project-name
, it would be more complex to create a regex pattern (e.g., we would have to find the pattern again) when trying to use other URLs, for example, example.com/project-name, etc
.
Tell us about your feature request
It's not possible to enter project name as this:
github.com/wojcraft/project-name
- I've got used to this naming for learning and I see it also affects imports. Can you help me with that?Here is screenshot of a input that needs to be modified in order to solve this request
Disclaimer