Extract .xsaccess files as JSON

This commit is contained in:
Mauro Baluda
2024-06-04 16:23:05 +02:00
parent 60970ff015
commit 73b18129d9
3 changed files with 9 additions and 5 deletions

View File

@@ -159,6 +159,7 @@ import com.semmle.util.trap.TrapWriter;
* <li>Files with base name "package.json" or "tsconfig.json", and files whose base name
* is of the form "codeql-javascript-*.json".
* <li>JavaScript, JSON or YAML files whose base name starts with ".eslintrc".
* <li>JSON files whose base name is ".xsaccess".
* <li>All extension-less files.
* </ul>
*
@@ -393,9 +394,10 @@ public class AutoBuild {
for (FileType filetype : defaultExtract)
for (String extension : filetype.getExtensions()) patterns.add("**/*" + extension);
// include .eslintrc files, package.json files, tsconfig.json files, and
// codeql-javascript-*.json files
// include .eslintrc files, .xaccess files, package.json files,
// tsconfig.json files, and codeql-javascript-*.json files
patterns.add("**/.eslintrc*");
patterns.add("**/.xaccess");
patterns.add("**/package.json");
patterns.add("**/tsconfig*.json");
patterns.add("**/codeql-javascript-*.json");

View File

@@ -184,8 +184,8 @@ public class FileExtractor {
if (super.contains(f, lcExt, config)) return true;
// detect JSON-encoded configuration files whose name starts with `.` and ends with `rc`
// (e.g., `.eslintrc` or `.babelrc`)
if (f.isFile() && f.getName().matches("\\..*rc")) {
// (e.g., `.eslintrc` or `.babelrc`) as well as `.xsaccess` files
if (f.isFile() && f.getName().matches("\\..*rc|\\.xsaccess")) {
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
// check whether the first two non-empty lines look like the start of a JSON object
// (two lines because the opening brace is usually on a line by itself)

View File

@@ -461,8 +461,10 @@ public class AutoBuildTests {
@Test
public void hiddenFiles() throws IOException {
Path eslintrc = addFile(true, LGTM_SRC, ".eslintrc.json");
Path eslintrc = addFile(true, LGTM_SRC, ".eslintrc.json", ".xsaccess");
hide(eslintrc);
Path xsaccess = addFile(true, LGTM_SRC, ".xsaccess");
hide(xsaccess);
runTest();
}