@@ -393,9 +393,6 @@ private boolean isAbsoluteImport(String importStr) {
393393 */
394394 public void validateImportsAndReads (Project project , Path pklModulePath ) {
395395 var imports = getImportsAndReads (pklModulePath );
396- if (imports == null ) {
397- return ;
398- }
399396 for (var importContext : imports ) {
400397 var importStr = importContext .stringValue ();
401398 var sourceSection = importContext .sourceSection ();
@@ -420,14 +417,14 @@ public void validateImportsAndReads(Project project, Path pklModulePath) {
420417 .toPklException (stackFrameTransformer , color );
421418 }
422419 var currentPath = pklModulePath .getParent ();
423- var importPath = Path . of ( importUri .getPath ());
420+ var importPath = importUri .getPath (). split ( "/" );
424421 // It's not good enough to just check the normalized path to see whether it exists within the
425422 // root dir.
426423 // It's possible that the import path resolves to a path outside the project dir,
427424 // and then back inside the project dir.
428- for (var i = 0 ; i < importPath . getNameCount (); i ++ ) {
429- var segment = importPath . getName ( i );
430- currentPath = currentPath .resolve (segment );
425+ for (var segment : importPath ) {
426+ // replace any possibly reserved filename characters with underscore.
427+ currentPath = currentPath .resolve (sanitizePathSegment ( segment ) );
431428 var normalized = currentPath .normalize ();
432429 if (!normalized .startsWith (project .getProjectDir ())) {
433430 throw new VmExceptionBuilder ()
@@ -440,6 +437,10 @@ public void validateImportsAndReads(Project project, Path pklModulePath) {
440437 }
441438 }
442439
440+ private String sanitizePathSegment (String segment ) {
441+ return segment .replaceAll ("[\\ \\ <>:\" |?*]" , "_" );
442+ }
443+
443444 private List <ImportsAndReadsParser .Entry > getImportsAndReads (Path pklModulePath ) {
444445 try {
445446 var moduleKey = ModuleKeys .file (pklModulePath );
0 commit comments