You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/04/22 07:47:17 UTC

[GitHub] [jena] kinow commented on a change in pull request #732: JENA-1887: SplitIRI fix

kinow commented on a change in pull request #732:
URL: https://github.com/apache/jena/pull/732#discussion_r412739669



##########
File path: jena-core/src/main/java/org/apache/jena/util/SplitIRI.java
##########
@@ -136,45 +135,66 @@ private static boolean needsEscape(char ch, boolean finalChar) {
     // @formatter:on
 
     /** Find the URI split point, return the index into the string that is the
-     *  first character of a legal Turtle local name.   
+     *  first character of a legal Turtle local name.
      * <p>
      * This is a pragmatic choice, not just finding the maximal point.
-     * For example, with escaping '/' can be included but that means 
+     * For example, with escaping '/' can be included but that means
      * {@code http://example/path/abc} could split to give {@code http://example/}
      * and {@code path/abc} .
      * <p>
-     * Split URN's after ':'.  
-     *   
+     * Split URN's after ':'.
+     *
      * @param uri URI string
      * @return The split point, or -1 for "not found".
      */
-    
     public static int splitpoint(String uri) {
         boolean isURN = uri.startsWith("urn:") ;
         // Fast track.  Still need to check validity of the prefix part.
         int idx1 = uri.lastIndexOf('#') ;
-        // Not so simple - \/ in local names 
+        // Not so simple - \/ in local names
         int idx2 = isURN ? uri.lastIndexOf(':') : uri.lastIndexOf('/') ;
 
         // If absolute.
-        int idx3 = uri.indexOf(':') ; 
-    
+        int idx3 = uri.indexOf(':') ;
+
         // Note: local names can't end in "." in Turtle.
         // This is handled by escape_PN_LOCAL_ESC which will escape it as "\."
-        
-        // Test the discovered local part.
-        // Limit is exclusive.
-        int limit = Math.max(idx1, idx2) ;
-        limit = Math.max(limit, idx3) ;
-        limit = Math.max(-1, limit) ;
-        
+
+        // Cases
+        //   "abc#def"
+        //   "/abc"
+        //   "/"
+        //   "/path/path#frag
+        //   "/path/path#abc/def" :: / in fragment, split is at the "#".
+
+        int limit;
+        if ( idx1 >= 0 && idx2 < 0 )
+            // no "/" (or ":" if a urn)
+            limit = idx1;
+        else if ( idx1 < 0 && idx2 >= 0 )
+            // no fragment
+            limit = idx2;
+        else
+            // Fragment and path.
+            // If "/" is in the fragment, it is not the split.
+            if ( idx1 >= 0 && idx2 >= 0 )

Review comment:
       Another interesting way to format code with comments! For one second thought we had two `else` statements. Nice!




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org