Skip to content

Commit

Permalink
detect uri pattern and not windows drives on File.dirname
Browse files Browse the repository at this point in the history
  • Loading branch information
mkristian committed Jun 17, 2015
1 parent 85d972c commit 0046bed
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
return runtime.newString(dirname(context, jfilename)).infectBy(filename);
}

private static Pattern PROTOCOL_PATTERN = Pattern.compile("^[a-z:]{2,}:/");
public static String dirname(ThreadContext context, String jfilename) {
String name = jfilename.replace('\\', '/');
int minPathLength = 1;
Expand All @@ -673,7 +674,7 @@ public static String dirname(ThreadContext context, String jfilename) {
}

// address all the url like paths first
if (name.contains(":/") || name.contains("!/")) {
if (PROTOCOL_PATTERN.matcher(name).matches() || name.contains("!/")) {
int start = Math.max(name.indexOf(":/"), name.indexOf("!/")) + 2;
String path = dirname(context, name.substring(start));
if (path.equals(".") || path.equals("/")) path = "";
Expand Down

0 comments on commit 0046bed

Please sign in to comment.