Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
27109d1a
Unverified
Commit
27109d1a
authored
Jun 14, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jun 14, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4505 from shuujii/fix-class-name-validation-in-Struct.new
Fix class name validation in `Struct.new`
parents
1a98b941
9bd692bc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
8 deletions
+13
-8
include/mruby/class.h
include/mruby/class.h
+1
-0
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
+1
-1
mrbgems/mruby-struct/test/struct.rb
mrbgems/mruby-struct/test/struct.rb
+4
-0
src/class.c
src/class.c
+7
-7
No files found.
include/mruby/class.h
View file @
27109d1a
...
...
@@ -88,6 +88,7 @@ MRB_API struct RClass* mrb_class_real(struct RClass* cl);
mrb_value
mrb_instance_new
(
mrb_state
*
mrb
,
mrb_value
cv
);
void
mrb_class_name_class
(
mrb_state
*
,
struct
RClass
*
,
struct
RClass
*
,
mrb_sym
);
mrb_bool
mrb_const_name_p
(
mrb_state
*
,
const
char
*
,
mrb_int
);
mrb_value
mrb_class_find_path
(
mrb_state
*
,
struct
RClass
*
);
void
mrb_gc_mark_mt
(
mrb_state
*
,
struct
RClass
*
);
size_t
mrb_gc_mark_mt_size
(
mrb_state
*
,
struct
RClass
*
);
...
...
mrbgems/mruby-struct/src/struct.c
View file @
27109d1a
...
...
@@ -212,7 +212,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass *kl
/* old style: should we warn? */
mrb_to_str
(
mrb
,
name
);
id
=
mrb_obj_to_sym
(
mrb
,
name
);
if
(
!
is_const_id
(
mrb
,
mrb_sym2name_len
(
mrb
,
id
,
NULL
)))
{
if
(
!
mrb_const_name_p
(
mrb
,
RSTRING_PTR
(
name
),
RSTRING_LEN
(
name
)))
{
mrb_name_error
(
mrb
,
id
,
"identifier %S needs to be constant"
,
name
);
}
if
(
mrb_const_defined_at
(
mrb
,
mrb_obj_value
(
klass
),
id
))
{
...
...
mrbgems/mruby-struct/test/struct.rb
View file @
27109d1a
...
...
@@ -181,6 +181,10 @@ assert("Struct.new does not allow array") do
end
end
assert
(
"Struct.new does not allow invalid class name"
)
do
assert_raise
(
NameError
)
{
Struct
.
new
(
"Test-"
,
:a
)
}
end
assert
(
"Struct.new generates subclass of Struct"
)
do
begin
original_struct
=
Struct
...
...
src/class.c
View file @
27109d1a
...
...
@@ -77,6 +77,12 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb
mrb_obj_iv_set_force
(
mrb
,
(
struct
RObject
*
)
c
,
nsym
,
name
);
}
mrb_bool
mrb_const_name_p
(
mrb_state
*
mrb
,
const
char
*
name
,
mrb_int
len
)
{
return
len
>
0
&&
ISUPPER
(
name
[
0
])
&&
mrb_ident_p
(
name
+
1
,
len
-
1
);
}
static
void
setup_class
(
mrb_state
*
mrb
,
struct
RClass
*
outer
,
struct
RClass
*
c
,
mrb_sym
id
)
{
...
...
@@ -1852,18 +1858,12 @@ mrb_mod_undef(mrb_state *mrb, mrb_value mod)
return
mrb_nil_value
();
}
static
mrb_bool
const_name_p
(
mrb_state
*
mrb
,
const
char
*
name
,
mrb_int
len
)
{
return
len
>
0
&&
ISUPPER
(
name
[
0
])
&&
mrb_ident_p
(
name
+
1
,
len
-
1
);
}
static
void
check_const_name_sym
(
mrb_state
*
mrb
,
mrb_sym
id
)
{
mrb_int
len
;
const
char
*
name
=
mrb_sym2name_len
(
mrb
,
id
,
&
len
);
if
(
!
const_name_p
(
mrb
,
name
,
len
))
{
if
(
!
mrb_
const_name_p
(
mrb
,
name
,
len
))
{
mrb_name_error
(
mrb
,
id
,
"wrong constant name %S"
,
mrb_sym2str
(
mrb
,
id
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment