@@ -331,15 +331,21 @@ describe('Marked renderer', () => {
331
331
] . join ( '\n' ) ;
332
332
333
333
it ( 'autolink enabled' , ( ) => {
334
- const result = r ( { text : body } ) ;
335
-
336
- result . should . eql ( [
334
+ let result = r ( { text : body } ) ;
335
+ const expected = [
337
336
'<p>Great website <a href="http://hexo.io/">http://hexo.io</a></p>' ,
338
337
'<p>A webpage <a href="http://www.example.com/">www.example.com</a></p>' ,
339
338
'<p><a href="http://hexo.io/">Hexo</a></p>' ,
340
339
'<p><a href="http://lorem.com/foo/">http://lorem.com/foo/</a></p>' ,
341
340
'<p><a href="http://dolor.com/">http://dolor.com</a></p>'
342
- ] . join ( '\n' ) + '\n' ) ;
341
+ ] . join ( '\n' ) + '\n' ;
342
+
343
+ result . should . eql ( expected ) ;
344
+
345
+ // try again
346
+ result = r ( { text : body } ) ;
347
+
348
+ result . should . eql ( expected ) ;
343
349
} ) ;
344
350
345
351
it ( 'autolink disabled' , ( ) => {
@@ -354,6 +360,17 @@ describe('Marked renderer', () => {
354
360
'<p><a href="http://dolor.com/">http://dolor.com</a></p>'
355
361
] . join ( '\n' ) + '\n' ) ;
356
362
} ) ;
363
+
364
+ it ( 'should not stack overflow' , function ( ) {
365
+ this . timeout ( 5000 ) ;
366
+ const body = 'Great website http://hexo.io' ;
367
+
368
+ ( ( ) => {
369
+ for ( let i = 0 ; i < 100000 ; i ++ ) {
370
+ r ( { text : body } ) ;
371
+ }
372
+ } ) . should . not . throw ( ) ;
373
+ } ) ;
357
374
} ) ;
358
375
359
376
describe ( 'mangle' , ( ) => {
@@ -924,12 +941,17 @@ describe('Marked renderer', () => {
924
941
925
942
const r = require ( '../lib/renderer' ) . bind ( hexo ) ;
926
943
927
- const result = r ( { text : body } ) ;
928
-
929
- result . should . eql ( [
944
+ let result = r ( { text : body } ) ;
945
+ const expected = [
930
946
`<p><img data-src="${ encodeURL ( urlA ) } ">` ,
931
947
`<img data-src="${ encodeURL ( urlB ) } "></p>\n`
932
- ] . join ( '\n' ) ) ;
948
+ ] . join ( '\n' ) ;
949
+
950
+ result . should . eql ( expected ) ;
951
+ // try again
952
+ result = r ( { text : body } ) ;
953
+
954
+ result . should . eql ( expected ) ;
933
955
} ) ;
934
956
935
957
it ( 'should execute filter registered to marked:tokenizer' , ( ) => {
@@ -951,8 +973,12 @@ describe('Marked renderer', () => {
951
973
952
974
const r = require ( '../lib/renderer' ) . bind ( hexo ) ;
953
975
954
- const result = r ( { text : body } ) ;
955
- result . should . eql ( `<p>${ escapeHTML ( smartypants ( body ) ) } </p>\n` ) ;
976
+ let result = r ( { text : body } ) ;
977
+ const expected = `<p>${ escapeHTML ( smartypants ( body ) ) } </p>\n` ;
978
+ result . should . eql ( expected ) ;
979
+ // try again
980
+ result = r ( { text : body } ) ;
981
+ result . should . eql ( expected ) ;
956
982
} ) ;
957
983
958
984
it ( 'should execute filter registered to marked:extensions' , ( ) => {
@@ -983,8 +1009,12 @@ describe('Marked renderer', () => {
983
1009
984
1010
const r = require ( '../lib/renderer' ) . bind ( hexo ) ;
985
1011
986
- const result = r ( { text : body } ) ;
987
- result . should . eql ( `<p class="math block">${ escapeHTML ( 'E=mc^2' ) } </p>\n` ) ;
1012
+ let result = r ( { text : body } ) ;
1013
+ const expected = `<p class="math block">${ escapeHTML ( 'E=mc^2' ) } </p>\n` ;
1014
+ result . should . eql ( expected ) ;
1015
+ // try again
1016
+ result = r ( { text : body } ) ;
1017
+ result . should . eql ( expected ) ;
988
1018
} ) ;
989
1019
} ) ;
990
1020
0 commit comments