Skip to content

Commit e9de73b

Browse files
committed
JS: Add environment variable to opt out of the behaviour if needed
1 parent 38eef8a commit e9de73b

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,10 @@ private void setupFilters() {
408408
for (String extension : fileTypes.keySet()) patterns.add("**/*" + extension);
409409

410410
// exclude files whose name strongly suggests they are minified
411-
patterns.add("-**/*.min.js");
412-
patterns.add("-**/*-min.js");
411+
if (!EnvironmentVariables.allowMinifiedFiles()) {
412+
patterns.add("-**/*.min.js");
413+
patterns.add("-**/*-min.js");
414+
}
413415

414416
// exclude `node_modules` and `bower_components`
415417
patterns.add("-**/node_modules");
@@ -1074,6 +1076,7 @@ private ExtractorConfig mkExtractorConfig() {
10741076
config = config.withSourceType(getSourceType());
10751077
config = config.withVirtualSourceRoot(virtualSourceRoot);
10761078
if (defaultEncoding != null) config = config.withDefaultEncoding(defaultEncoding);
1079+
config = config.withAllowMinified(EnvironmentVariables.allowMinifiedFiles());
10771080
return config;
10781081
}
10791082

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,12 @@ public static String getWipDatabase() {
101101
public static boolean isActionsExtractor() {
102102
return Env.systemEnv().getNonEmpty(CODEQL_EXTRACTOR_ACTIONS_WIP_DATABASE_ENV_VAR) != null;
103103
}
104+
105+
public static boolean allowMinifiedFiles() {
106+
String env = Env.systemEnv().getNonEmpty("CODEQL_EXTRACTOR_JAVASCRIPT_ALLOW_MINIFIED_FILES");
107+
if (env == null) {
108+
return false; // default is to not allow minified files
109+
}
110+
return Boolean.parseBoolean(env);
111+
}
104112
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ public Set<String> getPredefinedGlobals() {
205205
/** Should parse errors be reported as violations instead of aborting extraction? */
206206
private boolean tolerateParseErrors;
207207

208+
/** Should minified files be allowed? */
209+
private boolean allowMinified;
210+
208211
/** How should HTML files be extracted? */
209212
private HtmlPopulator.Config htmlHandling;
210213

@@ -236,6 +239,7 @@ public ExtractorConfig(boolean experimental) {
236239
this.sourceType = SourceType.AUTO;
237240
this.htmlHandling = HtmlPopulator.Config.ELEMENTS;
238241
this.tolerateParseErrors = true;
242+
this.allowMinified = false;
239243
if (experimental) {
240244
this.mozExtensions = true;
241245
this.jscript = true;
@@ -258,6 +262,7 @@ public ExtractorConfig(ExtractorConfig that) {
258262
this.v8Extensions = that.v8Extensions;
259263
this.e4x = that.e4x;
260264
this.tolerateParseErrors = that.tolerateParseErrors;
265+
this.allowMinified = that.allowMinified;
261266
this.fileType = that.fileType;
262267
this.sourceType = that.sourceType;
263268
this.htmlHandling = that.htmlHandling;
@@ -357,6 +362,16 @@ public ExtractorConfig withTolerateParseErrors(boolean tolerateParseErrors) {
357362
return res;
358363
}
359364

365+
public boolean isAllowMinified() {
366+
return allowMinified;
367+
}
368+
369+
public ExtractorConfig withAllowMinified(boolean allowMinified) {
370+
ExtractorConfig res = new ExtractorConfig(this);
371+
res.allowMinified = allowMinified;
372+
return res;
373+
}
374+
360375
public boolean hasFileType() {
361376
return fileType != null;
362377
}
@@ -467,6 +482,8 @@ public String toString() {
467482
+ e4x
468483
+ ", tolerateParseErrors="
469484
+ tolerateParseErrors
485+
+ ", allowMinified="
486+
+ allowMinified
470487
+ ", htmlHandling="
471488
+ htmlHandling
472489
+ ", fileType="

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public ParseResultInfo extract(TextualExtractor textualExtractor) {
6262
LocationManager locationManager = textualExtractor.getLocationManager();
6363
String source = textualExtractor.getSource();
6464

65-
if (isMinified(source)) {
65+
if (!config.isAllowMinified() && isMinified(source)) {
6666
return ParseResultInfo.skipped("File appears to be minified.");
6767
}
6868

0 commit comments

Comments
 (0)