Skip to content

Commit

Permalink
standarize name
Browse files Browse the repository at this point in the history
  • Loading branch information
v9n committed Dec 27, 2024
1 parent ed4aa3e commit ef7bf2c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/taskengine/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package taskengine
import (
"context"
"fmt"
"regexp"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -98,8 +99,20 @@ func (v *VM) WithLogger(logger sdklogging.Logger) *VM {
}

func (v *VM) GetNodeNameAsVar(nodeID string) string {
// Replace invalid characters with _
re := regexp.MustCompile(`[^a-zA-Z0-9_$]`)
name := v.TaskNodes[nodeID].Name
return name
if name == "" {
name = nodeID
}
standardized := re.ReplaceAllString(v.TaskNodes[nodeID].Name, "_")

// Ensure the first character is valid
if len(standardized) == 0 || !regexp.MustCompile(`^[a-zA-Z_$]`).MatchString(standardized[:1]) {
standardized = "_" + standardized
}

return standardized
}

func NewVMWithData(taskID string, triggerMetadata *avsproto.TriggerMetadata, nodes []*avsproto.TaskNode, edges []*avsproto.TaskEdge) (*VM, error) {
Expand Down

0 comments on commit ef7bf2c

Please sign in to comment.