fix: improve JSON parsing in ForegroundInfo by cleaning packageInfo

This commit is contained in:
lilong.129
2025-06-26 13:48:42 +08:00
parent 90ce090e35
commit 51e106c9ad
2 changed files with 13 additions and 3 deletions

View File

@@ -1 +1 @@
v5.0.0-beta-2506261341
v5.0.0-beta-2506261348

View File

@@ -731,11 +731,21 @@ func (ad *ADBDriver) ForegroundInfo() (app types.AppInfo, err error) {
if err != nil {
return app, err
}
err = json.Unmarshal([]byte(strings.TrimSpace(packageInfo)), &app)
// Clean packageInfo: remove null bytes that cause JSON parsing issues
packageInfo = strings.ReplaceAll(packageInfo, "\x00", "")
// Check for empty response after cleaning
if strings.TrimSpace(packageInfo) == "" {
return app, errors.New("empty response from evalite process")
}
err = json.Unmarshal([]byte(packageInfo), &app)
if err != nil {
log.Error().Err(err).Str("packageInfo", packageInfo).Msg("get foreground app failed")
return app, err
}
return
return app, nil
}
func (ad *ADBDriver) SetIme(imeRegx string) error {