File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed
Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,9 @@ STATIC const mp_obj_type_t re_type = {
185185STATIC mp_obj_t mod_re_compile (uint n_args , const mp_obj_t * args ) {
186186 const char * re_str = mp_obj_str_get_str (args [0 ]);
187187 int size = re1_5_sizecode (re_str );
188+ if (size == -1 ) {
189+ goto error ;
190+ }
188191 mp_obj_re_t * o = m_new_obj_var (mp_obj_re_t , char , size );
189192 o -> base .type = & re_type ;
190193 int flags = 0 ;
@@ -193,6 +196,7 @@ STATIC mp_obj_t mod_re_compile(uint n_args, const mp_obj_t *args) {
193196 }
194197 int error = re1_5_compilecode (& o -> re , re_str );
195198 if (error != 0 ) {
199+ error :
196200 nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError , "Error in regex" ));
197201 }
198202 if (flags & FLAG_DEBUG ) {
Original file line number Diff line number Diff line change 6262m = re .match ('^ab$' , 'ab' ); print (m .group (0 ))
6363m = re .match ('a|b' , 'b' ); print (m .group (0 ))
6464m = re .match ('a|b|c' , 'c' ); print (m .group (0 ))
65+
66+ try :
67+ re .compile ("*" )
68+ except :
69+ print ("Caught invalid regex" )
You can’t perform that action at this time.
0 commit comments