mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* parse.y (reg_compile_gen): set error if failed to compile regexp
literal. [ruby-dev:31336] * re.c (rb_reg_compile): should not use regexp which could not get initialized. [ruby-dev:31333] return error message to let the parser know it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
46e848a65a
commit
d9274e7d6b
4 changed files with 31 additions and 10 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Thu Aug 2 23:36:23 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* parse.y (reg_compile_gen): set error if failed to compile regexp
|
||||||
|
literal. [ruby-dev:31336]
|
||||||
|
|
||||||
|
* re.c (rb_reg_compile): should not use regexp which could not get
|
||||||
|
initialized. [ruby-dev:31333]
|
||||||
|
return error message to let the parser know it.
|
||||||
|
|
||||||
Thu Aug 2 13:46:39 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Aug 2 13:46:39 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* sprintf.c (rb_f_sprintf): should not check positional number as
|
* sprintf.c (rb_f_sprintf): should not check positional number as
|
||||||
|
|
|
@ -440,7 +440,6 @@ VALUE rb_reg_match_pre(VALUE);
|
||||||
VALUE rb_reg_match_post(VALUE);
|
VALUE rb_reg_match_post(VALUE);
|
||||||
VALUE rb_reg_match_last(VALUE);
|
VALUE rb_reg_match_last(VALUE);
|
||||||
VALUE rb_reg_new(const char*, long, int);
|
VALUE rb_reg_new(const char*, long, int);
|
||||||
VALUE rb_reg_compile(const char*, long, int, const char*, int);
|
|
||||||
VALUE rb_reg_match(VALUE, VALUE);
|
VALUE rb_reg_match(VALUE, VALUE);
|
||||||
VALUE rb_reg_match2(VALUE);
|
VALUE rb_reg_match2(VALUE);
|
||||||
int rb_reg_options(VALUE);
|
int rb_reg_options(VALUE);
|
||||||
|
|
25
parse.y
25
parse.y
|
@ -419,6 +419,8 @@ extern int rb_dvar_defined(ID);
|
||||||
extern int rb_local_defined(ID);
|
extern int rb_local_defined(ID);
|
||||||
extern int rb_parse_in_eval(void);
|
extern int rb_parse_in_eval(void);
|
||||||
|
|
||||||
|
static VALUE reg_compile_gen(struct parser_params*, const char *, long, int);
|
||||||
|
#define reg_compile(ptr,len,options) reg_compile_gen(parser, ptr, len, options)
|
||||||
#else
|
#else
|
||||||
#define remove_begin(node) (node)
|
#define remove_begin(node) (node)
|
||||||
#endif /* !RIPPER */
|
#endif /* !RIPPER */
|
||||||
|
@ -3611,18 +3613,16 @@ regexp : tREGEXP_BEG xstring_contents tREGEXP_END
|
||||||
int options = $3;
|
int options = $3;
|
||||||
NODE *node = $2;
|
NODE *node = $2;
|
||||||
if (!node) {
|
if (!node) {
|
||||||
node = NEW_LIT(rb_reg_compile("", 0, options & ~RE_OPTION_ONCE,
|
node = NEW_LIT(reg_compile("", 0, options));
|
||||||
ruby_sourcefile, ruby_sourceline));
|
|
||||||
}
|
}
|
||||||
else switch (nd_type(node)) {
|
else switch (nd_type(node)) {
|
||||||
case NODE_STR:
|
case NODE_STR:
|
||||||
{
|
{
|
||||||
VALUE src = node->nd_lit;
|
VALUE src = node->nd_lit;
|
||||||
nd_set_type(node, NODE_LIT);
|
nd_set_type(node, NODE_LIT);
|
||||||
node->nd_lit = rb_reg_compile(RSTRING_PTR(src),
|
node->nd_lit = reg_compile(RSTRING_PTR(src),
|
||||||
RSTRING_LEN(src),
|
RSTRING_LEN(src),
|
||||||
options & ~RE_OPTION_ONCE,
|
options);
|
||||||
ruby_sourcefile, ruby_sourceline);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -8101,6 +8101,19 @@ dvar_curr_gen(struct parser_params *parser, ID id)
|
||||||
vtable_included(lvtbl->vars, id));
|
vtable_included(lvtbl->vars, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
reg_compile_gen(struct parser_params* parser, const char *ptr, long len, int options)
|
||||||
|
{
|
||||||
|
VALUE rb_reg_compile(const char *, long, int);
|
||||||
|
VALUE re = rb_reg_compile(ptr, len, (options) & ~RE_OPTION_ONCE);
|
||||||
|
|
||||||
|
if (TYPE(re) == T_STRING) {
|
||||||
|
compile_error(PARSER_ARG "%s", RSTRING_PTR(re));
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
return re;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_gc_mark_parser(void)
|
rb_gc_mark_parser(void)
|
||||||
{
|
{
|
||||||
|
|
6
re.c
6
re.c
|
@ -1521,14 +1521,14 @@ rb_reg_new(const char *s, long len, int options)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_reg_compile(const char *s, long len, int options, const char *file, int line)
|
rb_reg_compile(const char *s, long len, int options)
|
||||||
{
|
{
|
||||||
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
VALUE re = rb_reg_s_alloc(rb_cRegexp);
|
||||||
char err[ONIG_MAX_ERROR_MESSAGE_LEN];
|
char err[ONIG_MAX_ERROR_MESSAGE_LEN];
|
||||||
|
|
||||||
if (rb_reg_initialize(re, s, len, options, err) != 0) {
|
if (rb_reg_initialize(re, s, len, options, err) != 0) {
|
||||||
VALUE desc = rb_reg_desc(s, len, re);
|
VALUE desc = rb_reg_desc(s, len, 0);
|
||||||
rb_compile_error(file, line, "%s: %s", err, RSTRING_PTR(desc));
|
return rb_sprintf("%s: %s", err, RSTRING_PTR(desc));
|
||||||
}
|
}
|
||||||
FL_SET(re, REG_LITERAL);
|
FL_SET(re, REG_LITERAL);
|
||||||
return re;
|
return re;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue