diff options
author | Björn Gustavsson <[email protected]> | 2014-10-01 09:43:28 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-01-12 11:40:23 +0100 |
commit | cb6a006acbcec5aae7cf94f163f101fb6c9d439a (patch) | |
tree | 87f69ec423db79a378eb09d21decbe60ddff3a86 /lib/asn1/src/asn1ct_check.erl | |
parent | 6003a7c9d4319eba8eff7bfb8e4a73d3d1d38786 (diff) | |
download | otp-cb6a006acbcec5aae7cf94f163f101fb6c9d439a.tar.gz otp-cb6a006acbcec5aae7cf94f163f101fb6c9d439a.tar.bz2 otp-cb6a006acbcec5aae7cf94f163f101fb6c9d439a.zip |
Check CLASS names for validity
Class names must start with an uppercase letter and only contain
uppercase letters, digits, or hyphens. The parser will not allow
class names that don't start with an uppercase letter, so we don't
have to check that.
Diffstat (limited to 'lib/asn1/src/asn1ct_check.erl')
-rw-r--r-- | lib/asn1/src/asn1ct_check.erl | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl index a0253dba44..f1437597ec 100644 --- a/lib/asn1/src/asn1ct_check.erl +++ b/lib/asn1/src/asn1ct_check.erl @@ -438,7 +438,15 @@ do_checkp(S0, Name, #ptypedef{typespec=TypeSpec}=Type0) -> checkc(S, Names) -> check_fold(S, Names, fun do_checkc/3). -do_checkc(S0, Name, Class0) -> +do_checkc(S, Name, Class) -> + case is_classname(Name) of + false -> + return_asn1_error(S, Class, {illegal_class_name,Name}); + true -> + do_checkc_1(S, Name, Class) + end. + +do_checkc_1(S0, Name, Class0) -> {Class1,ClassSpec} = case Class0 of #classdef{} -> @@ -456,6 +464,14 @@ do_checkc(S0, Name, Class0) -> {error,Reason} -> error({class,Reason,S}) end. + +%% is_classname(Atom) -> true|false. +is_classname(Name) when is_atom(Name) -> + lists:all(fun($-) -> true; + (D) when $0 =< D, D =< $9 -> true; + (UC) when $A =< UC, UC =< $Z -> true; + (_) -> false + end, atom_to_list(Name)). checko(S,[Name|Os],Acc,ExclO,ExclOS) -> ?dbg("Checking object ~p~n",[Name]), @@ -6708,6 +6724,8 @@ asn1_error(S, Item, Error) -> format_error({already_defined,Name,PrevLine}) -> io_lib:format("the name ~p has already been defined at line ~p", [Name,PrevLine]); +format_error({illegal_class_name,Class}) -> + io_lib:format("the class name '~s' is illegal (it must start with an uppercase letter and only contain uppercase letters, digits, or hyphens)", [Class]); format_error({illegal_instance_of,Class}) -> io_lib:format("using INSTANCE OF on class '~s' is illegal, " "because INSTANCE OF may only be used on the class TYPE-IDENTIFIER", |