Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Stash API is useful for storing simple key/value pairs
# to preserve state between script runs
stash_set('key1', 'val1')
puts "key1: #{stash_get('key1')}"
stash_set('key2', 'val2')
puts "key2: #{stash_get('key2')}"
check_expression("'#{stash_get('key1')}' == 'val1'")
check_expression("'#{stash_get('key2')}' == 'val2'")
check_expression("'#{stash_keys().to_s}' == '[\"key1\", \"key2\"]'")
Expand Down
2 changes: 1 addition & 1 deletion openc3/lib/openc3/script/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def method_missing(method_name, *method_params, **kw_params)
disconnect = kw_params.delete(:disconnect)
# The only commands allowed through in disconnect mode are read-only
# Thus we allow the get, list, tlm and limits_enabled and subscribe methods
if method_name =~ /get_\w*|list_\w*|^tlm|limits_enabled|subscribe/
if method_name =~ /\w*_get$|^get_\w*|\w*_list$|^list_\w*|^tlm|^limits_enabled$|^subscribe$/

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data

This [regular expression](1) that depends on a [library input](2) may run slow on strings with many repetitions of 'a'. This [regular expression](3) that depends on a [library input](2) may run slow on strings with many repetitions of 'a'.
result = @json_drb.method_missing(method_name, *method_params, **kw_params)
end
# If they overrode the return value using the disconnect keyword then return that
Expand Down
11 changes: 8 additions & 3 deletions openc3/spec/script/script_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ module OpenC3
# Test that the disconnect mode value doesn't matter if we're connected
expect(tlm("INST HEALTH_STATUS TEMP1", disconnect: 10)).to be_nil
get_command("INST ABORT")
stash_set("SOMETHING")
stash_get("SOMETHING")
list_configs()
set_limits("INST", "HEALTH_STATUS", "TEMP1", 0.0, 10.0, 20.0, 30.0)
inject_tlm("INST", "HEALTH_STATUS", { TEMP1: 0, TEMP2: 0, TEMP3: 0, TEMP4: 0 })

expect(@methods).to eql %i(set_tlm tlm get_command set_limits inject_tlm)
expect(@methods).to eql %i(set_tlm tlm get_command stash_set stash_get list_configs set_limits inject_tlm)
end

it "disconnect_script should only allow read only methods" do
Expand All @@ -65,11 +67,14 @@ module OpenC3
# Test that we can override the return value in disconnect mode
expect(tlm("INST HEALTH_STATUS TEMP1", disconnect: 10)).to eql 10
get_command("INST ABORT")
stash_set("SOMETHING")
stash_get("SOMETHING")
list_configs()
set_limits("INST", "HEALTH_STATUS", "TEMP1", 0.0, 10.0, 20.0, 30.0)
inject_tlm("INST", "HEALTH_STATUS", { TEMP1: 0, TEMP2: 0, TEMP3: 0, TEMP4: 0 })

# In disconnect we don't pass through set commands or inject_tlm
expect(@methods).to eql %i(tlm get_command)
expect(@methods).to eql %i(tlm get_command stash_get list_configs)
end
end
end
Expand Down