Skip to content

Commit

Permalink
Disallow periods in parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Oct 29, 2024
1 parent 6cc33e6 commit 0f4813d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion openc3/lib/openc3/config/config_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def verify_num_parameters(min_num_params, max_num_params, usage = "")

# Verifies the indicated parameter in the config doesn't start or end
# with an underscore, doesn't contain a double underscore or double bracket,
# doesn't contain spaces and doesn't start with a close bracket.
# doesn't contain spaces or periods and doesn't start with a close bracket.
#
# @param [Integer] index The index of the parameter to check
def verify_parameter_naming(index, usage = "")
Expand All @@ -265,6 +265,9 @@ def verify_parameter_naming(index, usage = "")
if param.include? ' '
raise Error.new(self, "Parameter #{index} (#{param}) for #{@keyword} cannot contain a space (' ').", usage, @url)
end
if param.include? '.'
raise Error.new(self, "Parameter #{index} (#{param}) for #{@keyword} cannot contain a period ('.').", usage, @url)
end
if param.start_with?('}')
raise Error.new(self, "Parameter #{index} (#{param}) for #{@keyword} cannot start with a close bracket ('}').", usage, @url)
end
Expand Down
10 changes: 9 additions & 1 deletion openc3/python/openc3/config/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def verify_num_parameters(self, min_num_params, max_num_params, usage=""):

# Verifies the indicated parameter in the config doesn't start or end
# with an underscore, doesn't contain a double underscore or double bracket,
# doesn't contain spaces and doesn't start with a close bracket.
# doesn't contain spaces or periods and doesn't start with a close bracket.
#
# self.param [Integer] index The index of the parameter to check
def verify_parameter_naming(self, index, usage=""):
Expand Down Expand Up @@ -175,6 +175,14 @@ def verify_parameter_naming(self, index, usage=""):
self.url,
)

if "." in param:
raise ConfigParser.Error(
self,
f"Parameter {index} ({param}) for {self.keyword} cannot contain a periods ('.').",
usage,
self.url,
)

if param[0] == "}":
raise ConfigParser.Error(
self,
Expand Down
8 changes: 7 additions & 1 deletion openc3/python/test/config/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_verifies_the_maximum_number_of_parameters(self):

def test_verifies_parameters_do_not_have_bad_characters(self):
tf = tempfile.NamedTemporaryFile(mode="w+t")
line = "KEYWORD BAD1_ BAD__2 'BAD 3' }BAD_4 BAD[[5]]"
line = "KEYWORD BAD1_ BAD__2 'BAD 3' }BAD_4 BAD[[5]] BAD.6"
tf.writelines(line)
tf.seek(0)

Expand Down Expand Up @@ -409,6 +409,12 @@ def test_verifies_parameters_do_not_have_bad_characters(self):
self.cp.verify_parameter_naming,
5,
)
self.assertRaisesRegex(
ConfigParser.Error,
"cannot contain a period",
self.cp.verify_parameter_naming,
6,
)
tf.close()

def test_returns_an_error(self):
Expand Down
3 changes: 2 additions & 1 deletion openc3/spec/config/config_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ module OpenC3
describe "verify_parameter_naming" do
it "verifies parameters do not have bad characters" do
tf = Tempfile.new('unittest')
line = "KEYWORD BAD1_ BAD__2 'BAD 3' }BAD_4 BAD[[5]]"
line = "KEYWORD BAD1_ BAD__2 'BAD 3' }BAD_4 BAD[[5]] BAD.6"
tf.puts line
tf.close

Expand All @@ -428,6 +428,7 @@ module OpenC3
expect { @cp.verify_parameter_naming(3) }.to raise_error(ConfigParser::Error, /cannot contain a space/)
expect { @cp.verify_parameter_naming(4) }.to raise_error(ConfigParser::Error, /cannot start with a close bracket/)
expect { @cp.verify_parameter_naming(5) }.to raise_error(ConfigParser::Error, /cannot contain double brackets/)
expect { @cp.verify_parameter_naming(6) }.to raise_error(ConfigParser::Error, /cannot contain a period/)
end
tf.unlink
end
Expand Down

0 comments on commit 0f4813d

Please sign in to comment.