Skip to content

Commit 98da532

Browse files
committed
dont extract regular expressions from strings that are leaves in a string concat
1 parent f01ee59 commit 98da532

File tree

7 files changed

+843
-945
lines changed

7 files changed

+843
-945
lines changed

javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ public Label visit(Literal nd, Context c) {
596596
offsets.set(0, 1); // skip the initial '/'
597597
SourceMap sourceMap = SourceMap.legacyWithStartPos(SourceMap.fromString(nd.getRaw()).offsetBy(0, offsets), startPos);
598598
regexpExtractor.extract(source.substring(1, source.lastIndexOf('/')), sourceMap, nd, false);
599-
} else if (nd.isStringLiteral() && !c.isInsideType() && nd.getRaw().length() < 1000) {
599+
} else if (nd.isStringLiteral() && !c.isInsideType() && nd.getRaw().length() < 1000 && !c.isBinopOperand()) {
600600
SourceMap sourceMap = SourceMap.legacyWithStartPos(SourceMap.fromString(nd.getRaw()).offsetBy(0, makeStringLiteralOffsets(nd.getRaw())), startPos);
601601
regexpExtractor.extract(valueString, sourceMap, nd, true);
602602

javascript/extractor/tests/es2015/output/trap/properties.js.trap

Lines changed: 106 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -287,150 +287,144 @@ enclosing_stmt(#20097,#20083)
287287
expr_containers(#20097,#20001)
288288
literals("prop","""prop""",#20097)
289289
#20098=*
290-
regexpterm(#20098,14,#20097,0,"prop")
291-
#20099=@"loc,{#10000},3,11,3,14"
292-
locations_default(#20099,#10000,3,11,3,14)
290+
exprs(#20098,13,#20095,1,"Math.random()")
291+
#20099=@"loc,{#10000},3,19,3,31"
292+
locations_default(#20099,#10000,3,19,3,31)
293293
hasLocation(#20098,#20099)
294-
regexp_const_value(#20098,"prop")
294+
enclosing_stmt(#20098,#20083)
295+
expr_containers(#20098,#20001)
295296
#20100=*
296-
exprs(#20100,13,#20095,1,"Math.random()")
297-
#20101=@"loc,{#10000},3,19,3,31"
298-
locations_default(#20101,#10000,3,19,3,31)
297+
exprs(#20100,14,#20098,-1,"Math.random")
298+
#20101=@"loc,{#10000},3,19,3,29"
299+
locations_default(#20101,#10000,3,19,3,29)
299300
hasLocation(#20100,#20101)
300301
enclosing_stmt(#20100,#20083)
301302
expr_containers(#20100,#20001)
302303
#20102=*
303-
exprs(#20102,14,#20100,-1,"Math.random")
304-
#20103=@"loc,{#10000},3,19,3,29"
305-
locations_default(#20103,#10000,3,19,3,29)
306-
hasLocation(#20102,#20103)
304+
exprs(#20102,79,#20100,0,"Math")
305+
hasLocation(#20102,#20037)
307306
enclosing_stmt(#20102,#20083)
308307
expr_containers(#20102,#20001)
308+
literals("Math","Math",#20102)
309+
#20103=@"var;{Math};{#20000}"
310+
variables(#20103,"Math",#20000)
311+
bind(#20102,#20103)
309312
#20104=*
310-
exprs(#20104,79,#20102,0,"Math")
311-
hasLocation(#20104,#20037)
313+
exprs(#20104,0,#20100,1,"random")
314+
hasLocation(#20104,#20041)
312315
enclosing_stmt(#20104,#20083)
313316
expr_containers(#20104,#20001)
314-
literals("Math","Math",#20104)
315-
#20105=@"var;{Math};{#20000}"
316-
variables(#20105,"Math",#20000)
317-
bind(#20104,#20105)
317+
literals("random","random",#20104)
318+
#20105=*
319+
exprs(#20105,3,#20093,1,"23")
320+
hasLocation(#20105,#20051)
321+
enclosing_stmt(#20105,#20083)
322+
expr_containers(#20105,#20001)
323+
literals("23","23",#20105)
324+
is_computed(#20093)
318325
#20106=*
319-
exprs(#20106,0,#20102,1,"random")
320-
hasLocation(#20106,#20041)
321-
enclosing_stmt(#20106,#20083)
322-
expr_containers(#20106,#20001)
323-
literals("random","random",#20106)
326+
properties(#20106,#20091,1,0,"x")
327+
hasLocation(#20106,#20055)
324328
#20107=*
325-
exprs(#20107,3,#20093,1,"23")
326-
hasLocation(#20107,#20051)
329+
exprs(#20107,0,#20106,0,"x")
330+
hasLocation(#20107,#20055)
327331
enclosing_stmt(#20107,#20083)
328332
expr_containers(#20107,#20001)
329-
literals("23","23",#20107)
330-
is_computed(#20093)
333+
literals("x","x",#20107)
331334
#20108=*
332-
properties(#20108,#20091,1,0,"x")
335+
exprs(#20108,79,#20106,1,"x")
333336
hasLocation(#20108,#20055)
337+
enclosing_stmt(#20108,#20083)
338+
expr_containers(#20108,#20001)
339+
literals("x","x",#20108)
340+
bind(#20108,#20081)
334341
#20109=*
335-
exprs(#20109,0,#20108,0,"x")
336-
hasLocation(#20109,#20055)
337-
enclosing_stmt(#20109,#20083)
338-
expr_containers(#20109,#20001)
339-
literals("x","x",#20109)
340-
#20110=*
341-
exprs(#20110,79,#20108,1,"x")
342-
hasLocation(#20110,#20055)
343-
enclosing_stmt(#20110,#20083)
344-
expr_containers(#20110,#20001)
345-
literals("x","x",#20110)
346-
bind(#20110,#20081)
342+
properties(#20109,#20091,2,0,"m() { return 56; }")
343+
#20110=@"loc,{#10000},5,9,5,26"
344+
locations_default(#20110,#10000,5,9,5,26)
345+
hasLocation(#20109,#20110)
347346
#20111=*
348-
properties(#20111,#20091,2,0,"m() { return 56; }")
349-
#20112=@"loc,{#10000},5,9,5,26"
350-
locations_default(#20112,#10000,5,9,5,26)
351-
hasLocation(#20111,#20112)
352-
#20113=*
353-
exprs(#20113,0,#20111,0,"m")
354-
hasLocation(#20113,#20059)
355-
enclosing_stmt(#20113,#20083)
356-
expr_containers(#20113,#20001)
357-
literals("m","m",#20113)
347+
exprs(#20111,0,#20109,0,"m")
348+
hasLocation(#20111,#20059)
349+
enclosing_stmt(#20111,#20083)
350+
expr_containers(#20111,#20001)
351+
literals("m","m",#20111)
352+
#20112=*
353+
exprs(#20112,9,#20109,1,"() { return 56; }")
354+
#20113=@"loc,{#10000},5,10,5,26"
355+
locations_default(#20113,#10000,5,10,5,26)
356+
hasLocation(#20112,#20113)
357+
enclosing_stmt(#20112,#20083)
358+
expr_containers(#20112,#20001)
358359
#20114=*
359-
exprs(#20114,9,#20111,1,"() { return 56; }")
360-
#20115=@"loc,{#10000},5,10,5,26"
361-
locations_default(#20115,#10000,5,10,5,26)
362-
hasLocation(#20114,#20115)
363-
enclosing_stmt(#20114,#20083)
364-
expr_containers(#20114,#20001)
360+
scopes(#20114,1)
361+
scopenodes(#20112,#20114)
362+
scopenesting(#20114,#20000)
363+
#20115=@"var;{arguments};{#20114}"
364+
variables(#20115,"arguments",#20114)
365+
is_arguments_object(#20115)
365366
#20116=*
366-
scopes(#20116,1)
367-
scopenodes(#20114,#20116)
368-
scopenesting(#20116,#20000)
369-
#20117=@"var;{arguments};{#20116}"
370-
variables(#20117,"arguments",#20116)
371-
is_arguments_object(#20117)
367+
stmts(#20116,1,#20112,-2,"{ return 56; }")
368+
#20117=@"loc,{#10000},5,13,5,26"
369+
locations_default(#20117,#10000,5,13,5,26)
370+
hasLocation(#20116,#20117)
371+
stmt_containers(#20116,#20112)
372372
#20118=*
373-
stmts(#20118,1,#20114,-2,"{ return 56; }")
374-
#20119=@"loc,{#10000},5,13,5,26"
375-
locations_default(#20119,#10000,5,13,5,26)
373+
stmts(#20118,9,#20116,0,"return 56;")
374+
#20119=@"loc,{#10000},5,15,5,24"
375+
locations_default(#20119,#10000,5,15,5,24)
376376
hasLocation(#20118,#20119)
377-
stmt_containers(#20118,#20114)
377+
stmt_containers(#20118,#20112)
378378
#20120=*
379-
stmts(#20120,9,#20118,0,"return 56;")
380-
#20121=@"loc,{#10000},5,15,5,24"
381-
locations_default(#20121,#10000,5,15,5,24)
382-
hasLocation(#20120,#20121)
383-
stmt_containers(#20120,#20114)
384-
#20122=*
385-
exprs(#20122,3,#20120,0,"56")
386-
hasLocation(#20122,#20069)
387-
enclosing_stmt(#20122,#20120)
388-
expr_containers(#20122,#20114)
389-
literals("56","56",#20122)
390-
is_method(#20111)
379+
exprs(#20120,3,#20118,0,"56")
380+
hasLocation(#20120,#20069)
381+
enclosing_stmt(#20120,#20118)
382+
expr_containers(#20120,#20112)
383+
literals("56","56",#20120)
384+
is_method(#20109)
385+
#20121=*
386+
entry_cfg_node(#20121,#20001)
387+
#20122=@"loc,{#10000},1,1,1,0"
388+
locations_default(#20122,#10000,1,1,1,0)
389+
hasLocation(#20121,#20122)
391390
#20123=*
392-
entry_cfg_node(#20123,#20001)
393-
#20124=@"loc,{#10000},1,1,1,0"
394-
locations_default(#20124,#10000,1,1,1,0)
395-
hasLocation(#20123,#20124)
396-
#20125=*
397-
exit_cfg_node(#20125,#20001)
398-
hasLocation(#20125,#20079)
391+
exit_cfg_node(#20123,#20001)
392+
hasLocation(#20123,#20079)
399393
successor(#20083,#20086)
400394
successor(#20091,#20097)
401-
successor(#20114,#20111)
395+
successor(#20112,#20109)
396+
#20124=*
397+
entry_cfg_node(#20124,#20112)
398+
#20125=@"loc,{#10000},5,10,5,9"
399+
locations_default(#20125,#10000,5,10,5,9)
400+
hasLocation(#20124,#20125)
402401
#20126=*
403-
entry_cfg_node(#20126,#20114)
404-
#20127=@"loc,{#10000},5,10,5,9"
405-
locations_default(#20127,#10000,5,10,5,9)
402+
exit_cfg_node(#20126,#20112)
403+
#20127=@"loc,{#10000},5,27,5,26"
404+
locations_default(#20127,#10000,5,27,5,26)
406405
hasLocation(#20126,#20127)
407-
#20128=*
408-
exit_cfg_node(#20128,#20114)
409-
#20129=@"loc,{#10000},5,27,5,26"
410-
locations_default(#20129,#10000,5,27,5,26)
411-
hasLocation(#20128,#20129)
412-
successor(#20118,#20122)
413-
successor(#20122,#20120)
414-
successor(#20120,#20128)
415-
successor(#20126,#20118)
416-
successor(#20113,#20114)
417-
successor(#20111,#20088)
418-
successor(#20110,#20108)
419-
successor(#20109,#20110)
420-
successor(#20108,#20113)
421-
successor(#20107,#20093)
422-
successor(#20106,#20102)
423-
successor(#20104,#20106)
424-
successor(#20102,#20100)
425-
successor(#20100,#20095)
426-
successor(#20097,#20104)
427-
successor(#20095,#20107)
428-
successor(#20093,#20109)
406+
successor(#20116,#20120)
407+
successor(#20120,#20118)
408+
successor(#20118,#20126)
409+
successor(#20124,#20116)
410+
successor(#20111,#20112)
411+
successor(#20109,#20088)
412+
successor(#20108,#20106)
413+
successor(#20107,#20108)
414+
successor(#20106,#20111)
415+
successor(#20105,#20093)
416+
successor(#20104,#20100)
417+
successor(#20102,#20104)
418+
successor(#20100,#20098)
419+
successor(#20098,#20095)
420+
successor(#20097,#20102)
421+
successor(#20095,#20105)
422+
successor(#20093,#20107)
429423
successor(#20090,#20091)
430-
successor(#20088,#20125)
424+
successor(#20088,#20123)
431425
successor(#20087,#20084)
432426
successor(#20086,#20087)
433427
successor(#20084,#20090)
434-
successor(#20123,#20083)
428+
successor(#20121,#20083)
435429
numlines(#10000,6,6,0)
436430
filetype(#10000,"javascript")

0 commit comments

Comments
 (0)