@@ -1002,4 +1002,61 @@ class AnsibleRunnerSpec extends Specification{
10021002 2 * ansibleVault. encryptVariable(_, _) >> " !vault | value"
10031003 }
10041004
1005+ def " node name sanitization: should sanitize node names with forward slashes for temp files" () {
1006+ given :
1007+ // Test case from real issue: node name with forward slashes
1008+ String nodeName = " /docker-runner-ansible-ssh-node-b-3"
1009+ String sanitized = nodeName. replaceAll(" [^a-zA-Z0-9._-]" , " _" )
1010+
1011+ expect :
1012+ sanitized == " _docker-runner-ansible-ssh-node-b-3"
1013+ // Verify sanitized name is filesystem-safe
1014+ ! sanitized. contains(" /" )
1015+ }
1016+
1017+ def " node name sanitization: should sanitize various special characters" () {
1018+ expect :
1019+ nodeName. replaceAll(" [^a-zA-Z0-9._-]" , " _" ) == expected
1020+
1021+ where :
1022+ nodeName || expected
1023+ " simple-node" || " simple-node"
1024+ " node.with.dots" || " node.with.dots"
1025+ " node_with_underscores" || " node_with_underscores"
1026+ " /docker-runner-ansible" || " _docker-runner-ansible"
1027+ " node:with:colons" || " node_with_colons"
1028+ " node with spaces" || " node_with_spaces"
1029+ " node\\ with\\ backslashes" || " node_with_backslashes"
1030+ " node*with?wildcards" || " node_with_wildcards"
1031+ " node|with|pipes" || " node_with_pipes"
1032+ " node<with>brackets" || " node_with_brackets"
1033+ " node\" with'quotes" || " node_with_quotes"
1034+ ' node@with#special$chars%' || " node_with_special_chars_"
1035+ " /path/to/node-123" || " _path_to_node-123"
1036+ }
1037+
1038+ def " node name sanitization: should preserve safe alphanumeric and allowed characters" () {
1039+ given :
1040+ String safeName = " my-node_123.server-A"
1041+ String sanitized = safeName. replaceAll(" [^a-zA-Z0-9._-]" , " _" )
1042+
1043+ expect :
1044+ sanitized == safeName // Should not be changed
1045+ }
1046+
1047+ def " node name sanitization: should handle empty and edge case node names" () {
1048+ expect :
1049+ nodeName. replaceAll(" [^a-zA-Z0-9._-]" , " _" ) == expected
1050+
1051+ where :
1052+ nodeName || expected
1053+ " " || " "
1054+ " 123" || " 123"
1055+ " ..." || " ..."
1056+ " ---" || " ---"
1057+ " ___" || " ___"
1058+ " a" || " a"
1059+ " /////" || " _____"
1060+ }
1061+
10051062}
0 commit comments