Verify that option names do not have invalid characters.

pull/34/head
Jussi Pakkanen 10 years ago
parent a337ab05e5
commit 3630febe1e
  1. 2
      interpreter.py
  2. 8
      optinterpreter.py
  3. 1
      test cases/failing/14 invalid option name/meson.build
  4. 1
      test cases/failing/14 invalid option name/meson_options.txt

@ -935,7 +935,7 @@ class Interpreter():
if not isinstance(optname, str):
raise InterpreterException('Argument of get_option must be a string.')
if self.subproject != '':
optname = self.subproject + '-' + optname
optname = self.subproject + ':' + optname
try:
return self.environment.get_coredata().get_builtin_option(optname)
except RuntimeError:

@ -14,7 +14,7 @@
import mparser
import coredata
import os
import os, re
forbidden_option_names = {'type': True,
'strip': True,
@ -34,6 +34,8 @@ forbidden_option_names = {'type': True,
class OptionException(coredata.MesonException):
pass
optname_regex = re.compile('[^a-zA-Z0-9_-]')
class UserOption:
def __init__(self, kwargs):
super().__init__()
@ -166,10 +168,12 @@ class OptionInterpreter:
opt_name = posargs[0]
if not isinstance(opt_name, str):
raise OptionException('Positional argument must be a string.')
if optname_regex.search(opt_name) is not None:
raise OptionException('Option names can only contain letters, numbers or dashes.')
if opt_name in forbidden_option_names:
raise OptionException('Option name %s is reserved.' % opt_name)
if self.subproject != '':
opt_name = self.subproject + '-' + opt_name
opt_name = self.subproject + ':' + opt_name
opt = option_types[opt_type](kwargs)
if opt.description == '':
opt.description = opt_name

@ -0,0 +1 @@
option('invalid/name', type : 'boolean', value : false)
Loading…
Cancel
Save