@@ -23,6 +23,8 @@ import { trimEnd } from "lodash";
2323
2424import { normalize as path_normalize } from "path" ;
2525
26+ import { filename_extension } from "@cocalc/util/misc" ;
27+
2628// Define some constants
2729const LOG_WRAP_LIMIT = 79 ;
2830const LATEX_WARNING_REGEX = / ^ L a T e X W a r n i n g : ( .* ) $ / ;
@@ -33,6 +35,26 @@ const LINES_REGEX = /lines? ([0-9]+)/;
3335// This is used to parse the package name from the package warnings
3436const PACKAGE_REGEX = / ^ (?: P a c k a g e | C l a s s | M o d u l e ) ( \b .+ \b ) W a r n i n g / ;
3537
38+ // Whitelist of text file extensions that can be used with \input{} or \include{}
39+ const ALLOWED_DEP_EXTENSIONS = [
40+ "bbx" ,
41+ "bib" ,
42+ "bst" ,
43+ "cbx" ,
44+ "cfg" ,
45+ "cls" ,
46+ "def" ,
47+ "lbx" ,
48+ "md" ,
49+ "pgf" ,
50+ "rnw" ,
51+ "rtex" ,
52+ "sty" ,
53+ "tex" ,
54+ "tikz" ,
55+ "txt" ,
56+ ] as const ;
57+
3658class LogText {
3759 private lines : string [ ] ;
3860 private row : number ;
@@ -224,14 +246,25 @@ export class LatexParser {
224246
225247 addDeps ( line : string ) : void {
226248 line = line . trim ( ) ;
227- // ignore absolute files
249+ // ignore absolute files (starting with /)
228250 if ( line [ 0 ] === "/" ) return ;
229251 if ( line [ line . length - 1 ] === "\\" ) {
230252 line = line . slice ( 0 , line . length - 1 ) ;
231253 }
232- // we only want to know about tex and bib files
233- const pl = line . toLowerCase ( ) ; // could be name.TEX
234- if ( ! pl . endsWith ( ".tex" ) && ! pl . endsWith ( ".bib" ) ) return ;
254+ // Skip files that contain a colon (like "master.pdf :")
255+ if ( line . includes ( ":" ) ) return ;
256+
257+ // Get the file extension (returns empty string if no extension)
258+ const ext = filename_extension ( line ) . toLowerCase ( ) ;
259+
260+ // If there's an extension, check if it's in the whitelist
261+ if ( ext ) {
262+ if ( ! ALLOWED_DEP_EXTENSIONS . includes ( ext as any ) ) {
263+ return ;
264+ }
265+ }
266+ // If no extension, include it (files without extensions are allowed)
267+
235268 this . deps . push ( line ) ;
236269 }
237270
@@ -306,7 +339,7 @@ export class LatexParser {
306339 const packageMatch = this . currentLine . match ( PACKAGE_REGEX ) ;
307340 if ( ! packageMatch ) return ;
308341 const packageName = packageMatch [ 1 ] ;
309- // Regex to get rid of the unnecesary (packagename) prefix in most multi-line warnings
342+ // Regex to get rid of the unnecessary (packagename) prefix in most multi-line warnings
310343 const prefixRegex = new RegExp ( `(?:\\(${ packageName } \\))*[\\s]*(.*)` , "i" ) ;
311344 // After every warning message there's a blank line, let's use it
312345 while ( ! ! ( this . currentLine = this . log . nextLine ( ) ) ) {
0 commit comments