From ad7fc34efd3defd1ecd56b015c23888a36479270 Mon Sep 17 00:00:00 2001 From: erik-krogh Date: Tue, 8 Nov 2022 23:01:19 +0100 Subject: [PATCH] extract .erb files as html --- .../com/semmle/js/extractor/AutoBuild.java | 2 +- .../semmle/js/extractor/FileExtractor.java | 2 +- .../src/com/semmle/js/extractor/Main.java | 2 +- .../extractor/tests/vue/input/rails.erb | 3 + .../tests/vue/output/trap/rails.erb.trap | 137 ++++++++++++++++++ 5 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 javascript/extractor/tests/vue/input/rails.erb create mode 100644 javascript/extractor/tests/vue/output/trap/rails.erb.trap diff --git a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java index 101b8094fdd..9d5a4c3b52b 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java +++ b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java @@ -141,7 +141,7 @@ import com.semmle.util.trap.TrapWriter; *
  • All JavaScript files, that is, files with one of the extensions supported by {@link * FileType#JS} (currently ".js", ".jsx", ".mjs", ".cjs", ".es6", ".es"). *
  • All HTML files, that is, files with with one of the extensions supported by {@link - * FileType#HTML} (currently ".htm", ".html", ".xhtm", ".xhtml", ".vue"). + * FileType#HTML} (currently ".htm", ".html", ".xhtm", ".xhtml", ".vue", ".erb"). *
  • All YAML files, that is, files with one of the extensions supported by {@link * FileType#YAML} (currently ".raml", ".yaml", ".yml"). *
  • Files with base name "package.json" or "tsconfig.json", and files whose base name diff --git a/javascript/extractor/src/com/semmle/js/extractor/FileExtractor.java b/javascript/extractor/src/com/semmle/js/extractor/FileExtractor.java index 42a41776916..77871a95fbe 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/FileExtractor.java +++ b/javascript/extractor/src/com/semmle/js/extractor/FileExtractor.java @@ -104,7 +104,7 @@ public class FileExtractor { /** Information about supported file types. */ public static enum FileType { - HTML(".htm", ".html", ".xhtm", ".xhtml", ".vue", ".hbs", ".ejs", ".njk") { + HTML(".htm", ".html", ".xhtm", ".xhtml", ".vue", ".hbs", ".ejs", ".njk", ".erb") { @Override public IExtractor mkExtractor(ExtractorConfig config, ExtractorState state) { return new HTMLExtractor(config, state); diff --git a/javascript/extractor/src/com/semmle/js/extractor/Main.java b/javascript/extractor/src/com/semmle/js/extractor/Main.java index 6a442d5396a..b97bb9f1ae8 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/Main.java +++ b/javascript/extractor/src/com/semmle/js/extractor/Main.java @@ -41,7 +41,7 @@ public class Main { * A version identifier that should be updated every time the extractor changes in such a way that * it may produce different tuples for the same file under the same {@link ExtractorConfig}. */ - public static final String EXTRACTOR_VERSION = "2022-09-19"; + public static final String EXTRACTOR_VERSION = "2022-11-09"; public static final Pattern NEWLINE = Pattern.compile("\n"); diff --git a/javascript/extractor/tests/vue/input/rails.erb b/javascript/extractor/tests/vue/input/rails.erb new file mode 100644 index 00000000000..d9df51cf3c0 --- /dev/null +++ b/javascript/extractor/tests/vue/input/rails.erb @@ -0,0 +1,3 @@ + diff --git a/javascript/extractor/tests/vue/output/trap/rails.erb.trap b/javascript/extractor/tests/vue/output/trap/rails.erb.trap new file mode 100644 index 00000000000..76af8c5c8d3 --- /dev/null +++ b/javascript/extractor/tests/vue/output/trap/rails.erb.trap @@ -0,0 +1,137 @@ +#10000=@"/rails.erb;sourcefile" +files(#10000,"/rails.erb") +#10001=@"/;folder" +folders(#10001,"/") +containerparent(#10001,#10000) +#10002=@"loc,{#10000},0,0,0,0" +locations_default(#10002,#10000,0,0,0,0) +hasLocation(#10000,#10002) +#20000=@"global_scope" +scopes(#20000,0) +#20001=* +#20002=@"script;{#10000},1,9" +#20003=* +lines(#20003,#20002,""," +") +#20004=@"loc,{#10000},1,9,1,8" +locations_default(#20004,#10000,1,9,1,8) +hasLocation(#20003,#20004) +#20005=* +lines(#20005,#20002," console.log(""FOO"");"," +") +#20006=@"loc,{#10000},2,1,2,21" +locations_default(#20006,#10000,2,1,2,21) +hasLocation(#20005,#20006) +indentation(#10000,2," ",2) +numlines(#20002,2,1,0) +#20007=* +tokeninfo(#20007,6,#20002,0,"console") +#20008=@"loc,{#10000},2,3,2,9" +locations_default(#20008,#10000,2,3,2,9) +hasLocation(#20007,#20008) +#20009=* +tokeninfo(#20009,8,#20002,1,".") +#20010=@"loc,{#10000},2,10,2,10" +locations_default(#20010,#10000,2,10,2,10) +hasLocation(#20009,#20010) +#20011=* +tokeninfo(#20011,6,#20002,2,"log") +#20012=@"loc,{#10000},2,11,2,13" +locations_default(#20012,#10000,2,11,2,13) +hasLocation(#20011,#20012) +#20013=* +tokeninfo(#20013,8,#20002,3,"(") +#20014=@"loc,{#10000},2,14,2,14" +locations_default(#20014,#10000,2,14,2,14) +hasLocation(#20013,#20014) +#20015=* +tokeninfo(#20015,4,#20002,4,"""FOO""") +#20016=@"loc,{#10000},2,15,2,19" +locations_default(#20016,#10000,2,15,2,19) +hasLocation(#20015,#20016) +#20017=* +tokeninfo(#20017,8,#20002,5,")") +#20018=@"loc,{#10000},2,20,2,20" +locations_default(#20018,#10000,2,20,2,20) +hasLocation(#20017,#20018) +#20019=* +tokeninfo(#20019,8,#20002,6,";") +#20020=@"loc,{#10000},2,21,2,21" +locations_default(#20020,#10000,2,21,2,21) +hasLocation(#20019,#20020) +#20021=* +tokeninfo(#20021,0,#20002,7,"") +#20022=@"loc,{#10000},3,1,3,0" +locations_default(#20022,#10000,3,1,3,0) +hasLocation(#20021,#20022) +toplevels(#20002,1) +#20023=@"loc,{#10000},1,9,3,0" +locations_default(#20023,#10000,1,9,3,0) +hasLocation(#20002,#20023) +#20024=* +stmts(#20024,2,#20002,0,"console.log(""FOO"");") +#20025=@"loc,{#10000},2,3,2,21" +locations_default(#20025,#10000,2,3,2,21) +hasLocation(#20024,#20025) +stmt_containers(#20024,#20002) +#20026=* +exprs(#20026,13,#20024,0,"console.log(""FOO"")") +#20027=@"loc,{#10000},2,3,2,20" +locations_default(#20027,#10000,2,3,2,20) +hasLocation(#20026,#20027) +enclosing_stmt(#20026,#20024) +expr_containers(#20026,#20002) +#20028=* +exprs(#20028,14,#20026,-1,"console.log") +#20029=@"loc,{#10000},2,3,2,13" +locations_default(#20029,#10000,2,3,2,13) +hasLocation(#20028,#20029) +enclosing_stmt(#20028,#20024) +expr_containers(#20028,#20002) +#20030=* +exprs(#20030,79,#20028,0,"console") +hasLocation(#20030,#20008) +enclosing_stmt(#20030,#20024) +expr_containers(#20030,#20002) +literals("console","console",#20030) +#20031=@"var;{console};{#20000}" +variables(#20031,"console",#20000) +bind(#20030,#20031) +#20032=* +exprs(#20032,0,#20028,1,"log") +hasLocation(#20032,#20012) +enclosing_stmt(#20032,#20024) +expr_containers(#20032,#20002) +literals("log","log",#20032) +#20033=* +exprs(#20033,4,#20026,0,"""FOO""") +hasLocation(#20033,#20016) +enclosing_stmt(#20033,#20024) +expr_containers(#20033,#20002) +literals("FOO","""FOO""",#20033) +#20034=* +regexpterm(#20034,14,#20033,0,"FOO") +#20035=@"loc,{#10000},2,16,2,18" +locations_default(#20035,#10000,2,16,2,18) +hasLocation(#20034,#20035) +regexp_const_value(#20034,"FOO") +#20036=* +entry_cfg_node(#20036,#20002) +hasLocation(#20036,#20004) +#20037=* +exit_cfg_node(#20037,#20002) +hasLocation(#20037,#20022) +successor(#20024,#20030) +successor(#20033,#20026) +successor(#20032,#20028) +successor(#20030,#20032) +successor(#20028,#20033) +successor(#20026,#20037) +successor(#20036,#20024) +toplevel_parent_xml_node(#20002,#20001) +xmlElements(#20001,"script",#10000,0,#10000) +#20038=@"loc,{#10000},1,1,3,9" +locations_default(#20038,#10000,1,1,3,9) +xmllocations(#20001,#20038) +numlines(#10000,3,1,0) +filetype(#10000,"html")