You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "mbeckerle (via GitHub)" <gi...@apache.org> on 2023/06/22 18:40:54 UTC

[GitHub] [daffodil] mbeckerle commented on a diff in pull request #1037: Allows include/import schemaLocations to have relative up path steps.

mbeckerle commented on code in PR #1037:
URL: https://github.com/apache/daffodil/pull/1037#discussion_r1238903981


##########
daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/DaffodilXMLLoader.scala:
##########
@@ -250,7 +262,11 @@ class DFDLCatalogResolver private ()
         // use the systemId (which comes from the schemaLocation attribute)
         // and the classpath.
         val baseURI = if (baseURIString == null) None else Some(new URI(baseURIString))
-        val optURI = Misc.getResourceRelativeOption(sysId, baseURI)
+        // try it as a direct classpath resolution first, and if that fails,
+        // try removing all the upward path steps (if any).
+        val optURI = Misc.getResourceRelativeOption(sysId, baseURI).orElse(
+          Misc.getResourceRelativeOption(removeInitialUpwardPathSteps(sysId), baseURI)

Review Comment:
   Well, the corner case you suggest does and could happen.
   
   But not if schemas use package-like names for directories, or very unique file names. 
   
   It certainly is possible to get the number of "../" wrong, but it's also possible to cut/paste the wrong root-path component name and then forget to edit it. 
   
   One nice thing is for the relative paths within a schema, the IDE highlights them if they're wrong.  Not inter-schema however. 
   
   I just tested all this with a few schemas. I used Janap128 and OTH-Gold (which are Owl's schemas). I changed all the schemaLocation paths that were relative to use relative up-steps, and the classpath/inter-component ones to have up-steps to the root.  
   
   All worked first try, once I put this same resolver change into the Owl xsat2 library. 
   
   I suggest this: we shouldn't let the perfect be the enemy of the good here. This change will really help out people trying to use DFDL schemas to validate XML data using, well, not-daffodil. Ex: C-based tooling. 
   
   If debugging include/import schemaLocations becomes problematic, then we can make changes to getResourceRelativeOption along the lines of what you are suggesting. We're writing our own class path search in that case but that would be ok because we could get much better diagnostics. 
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org