Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.deploy

import java.net.{URI, URISyntaxException}

import scala.collection.mutable.ListBuffer

import org.apache.log4j.Level
Expand Down Expand Up @@ -114,5 +116,12 @@ private[spark] class ClientArguments(args: Array[String]) {
}

object ClientArguments {
def isValidJarUrl(s: String): Boolean = s.matches("(.+):(.+)jar")
def isValidJarUrl(s: String): Boolean = {
try {
val uri = new URI(s)
uri.getScheme != null && uri.getAuthority != null && s.endsWith("jar")
} catch {
case _: URISyntaxException => false
}
}
}
6 changes: 6 additions & 0 deletions core/src/test/scala/org/apache/spark/deploy/ClientSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class ClientSuite extends FunSuite with Matchers {
ClientArguments.isValidJarUrl("hdfs://someHost:1234/foo") should be (false)
ClientArguments.isValidJarUrl("/missing/a/protocol/jarfile.jar") should be (false)
ClientArguments.isValidJarUrl("not-even-a-path.jar") should be (false)

// No authority
ClientArguments.isValidJarUrl("hdfs:someHost:1234/jarfile.jar") should be (false)

// Invalid syntax
ClientArguments.isValidJarUrl("hdfs:")should be (false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space before should, but I'll fix this when I merge

}

}