From a8fbaa5d0c269ca5a77c648e79bd6d25caaace70 Mon Sep 17 00:00:00 2001 From: "konstantin.annikov" Date: Tue, 21 Feb 2023 16:22:58 +0100 Subject: [PATCH] IDEA-302727 [Repair Utility] - Crash if IDE is in non-ascii path GitOrigin-RevId: a6486afd75c502444fac25585aeebe4e0732bcab --- native/repair-utility/cmd/root.go | 1 + native/repair-utility/helpers/ide.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/native/repair-utility/cmd/root.go b/native/repair-utility/cmd/root.go index e54071b72bef..171c277f8bf6 100644 --- a/native/repair-utility/cmd/root.go +++ b/native/repair-utility/cmd/root.go @@ -62,6 +62,7 @@ func initPath() { ideaBinary, err = helpers.SelectIdeaBinary() logger.ExitWithExceptionOnError(err) } + helpers.CurrentIde.CheckIfPathIsAllowed(ideaBinary) helpers.CurrentIde.SetBinaryToWrokWith(ideaBinary) } diff --git a/native/repair-utility/helpers/ide.go b/native/repair-utility/helpers/ide.go index c30769db1e53..36f914cb49cf 100644 --- a/native/repair-utility/helpers/ide.go +++ b/native/repair-utility/helpers/ide.go @@ -2,6 +2,7 @@ package helpers import ( "encoding/json" + "errors" "io/ioutil" "log" "os" @@ -11,6 +12,7 @@ import ( "runtime" "strconv" "strings" + "unicode" ) type IdeInfo struct { @@ -299,3 +301,18 @@ func (ide *IDE) RunIde() *os.Process { logger.DebugLogger.Println("Started the IDE with PID " + strconv.Itoa(cmd.Process.Pid)) return cmd.Process } + +func (ide *IDE) CheckIfPathIsAllowed(path string) { + if !isASCII(path) { + logger.FatalLogger.Fatal(errors.New("The path contains non-ASCII characters. IDE cannot run here: " + path)) + } +} + +func isASCII(s string) bool { + for _, c := range s { + if c > unicode.MaxASCII { + return false + } + } + return true +}