Skip to content

Commit

Permalink
@W-8522881@ Invalidate input URL if it contains special characters (#534
Browse files Browse the repository at this point in the history
)

* encoding url with uri in text

* fixing test

* address review feedback

* fix indent and compile error

* Change strategy to returning None if special chars in url domain

* cleanup
  • Loading branch information
winterslu authored Jan 8, 2021
1 parent 91724f1 commit 37df638
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import com.twitter.chill.Base64.{InputStream => Base64InputStream}
import org.apache.commons.io.input.CharSequenceInputStream
import org.apache.commons.validator.routines.UrlValidator

import scala.util.Try

/**
* Text value representation
*
Expand Down Expand Up @@ -171,7 +173,7 @@ class URL(value: Option[String]) extends Text(value){
* RFC2396 (http://www.ietf.org/rfc/rfc2396.txt)
* Default valid protocols are: http, https, ftp.
*/
def isValid: Boolean = value.exists(UrlValidator.getInstance().isValid)
def isValid: Boolean = value.exists(v => UrlValidator.getInstance().isValid(v) && Try(new java.net.URL(v)).isSuccess)
/**
* Verifies if the url is of correct form of "Uniform Resource Identifiers (URI): Generic Syntax"
* RFC2396 (http://www.ietf.org/rfc/rfc2396.txt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class URLTest extends PropSpec with PropertyChecks with TestCommon {
Some("ftp://.codomain"),
Some("https://.codomain"),
Some("//domain.nambia"),
Some("http://\u00ff\u0080\u007f\u0000.com") // scalastyle:off
Some("http://\u00ff\u0080\u007f\u0000.com"), // scalastyle:off
Some("http://specialchars.@.com")
)

val goodOnes = Table("good ones",
Expand Down

0 comments on commit 37df638

Please sign in to comment.