File tree 3 files changed +48
-0
lines changed
3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 269
269
return result ;
270
270
}
271
271
272
+ /***********************************************************************
273
+ **
274
+ */ void Assert_Max_Refines (REBVAL * ds , REBCNT limit )
275
+ /*
276
+ ** Scans the stack for function refinements
277
+ ** and throw an error if exeeds given limit
278
+ **
279
+ ***********************************************************************/
280
+ {
281
+ REBINT n ;
282
+ REBCNT count = 0 ;
283
+ REBINT len = DS_ARGC ;
284
+
285
+ for (n = 1 ; n <= len ; n ++ ) {
286
+ if (D_REF (n ))
287
+ if (count ++ == limit ) Trap0 (RE_BAD_REFINES );
288
+ }
289
+ }
290
+
272
291
273
292
/***********************************************************************
274
293
**
Original file line number Diff line number Diff line change @@ -237,6 +237,8 @@ static REBSER *Read_All_File(char *fname)
237
237
REBINT n = -1 ;
238
238
REBVAL * ret = D_RET ;
239
239
240
+ Assert_Max_Refines (ds , D_REF (9 ) ? 2 : 1 ); // prevent too many refines like: now/year/month
241
+
240
242
OS_GET_TIME (& dat );
241
243
if (!D_REF (9 )) dat .nano = 0 ; // Not /precise
242
244
Set_Date (ret , & dat );
Original file line number Diff line number Diff line change @@ -151,4 +151,31 @@ Rebol [
151
151
152
152
===end-group===
153
153
154
+
155
+ ===start-group=== "NOW"
156
+ --test-- "now"
157
+ --assert integer? now /year
158
+ --assert integer? now /month
159
+ --assert integer? now /day
160
+ --assert time? now /time
161
+ --assert time? now /zone
162
+ --assert date? now /date
163
+ --assert integer? now /weekday
164
+ --assert integer? now /yearday
165
+ --assert date? now /utc
166
+
167
+ --test-- "now/precise"
168
+ --assert time? now /time/precise
169
+ --assert date? now /utc/precise
170
+ --assert date? now /precise
171
+ --assert integer? now /year/precise ; precise ignored
172
+
173
+ --test-- "now with too many refines"
174
+ ;@@ https://github.com/Oldes/Rebol-issues/issues/2286
175
+ --assert error? try [now /time/day ]
176
+ --assert error? try [now /time/day/precise ]
177
+ --assert error? try [now /utc/month ]
178
+
179
+ ===end-group===
180
+
154
181
~~~end-file~~~
You can’t perform that action at this time.
0 commit comments