lib/bindata/dsl.rb in bindata-1.2.1 vs lib/bindata/dsl.rb in bindata-1.2.2

- old
+ new

@@ -21,10 +21,14 @@ end def method_missing(symbol, *args, &block) #:nodoc: dsl_parser.__send__(symbol, *args, &block) end + + # Assert object is not an array or string. + def to_ary; nil; end + def to_str; nil; end end # An array containing a field definition of the form # expected by BinData::Struct. class UnSanitizedField < ::Array @@ -228,10 +232,14 @@ if must_have_a_name_failed?(name) dsl_raise SyntaxError, "field must have a name" end + if malformed_name?(name) + dsl_raise NameError.new("", name), "field '#{name}' is an illegal fieldname" + end + if duplicate_name?(name) dsl_raise SyntaxError, "duplicate field '#{name}'" end if name_shadows_method?(name) @@ -262,9 +270,13 @@ (name != "" and all_names_blank) or (name == "" and no_names_blank) else false end + end + + def malformed_name?(name) + name != "" and /^[a-z_]\w*$/ !~ name end def duplicate_name?(name) name != "" and fields.field_names.include?(name) end