Skip to content

Commit 37df638

Browse files
authored
@W-8522881@ Invalidate input URL if it contains special characters (#534)
* 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
1 parent 91724f1 commit 37df638

File tree

2 files changed

+5
-2
lines changed
  • features/src

2 files changed

+5
-2
lines changed

features/src/main/scala/com/salesforce/op/features/types/Text.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import com.twitter.chill.Base64.{InputStream => Base64InputStream}
3838
import org.apache.commons.io.input.CharSequenceInputStream
3939
import org.apache.commons.validator.routines.UrlValidator
4040

41+
import scala.util.Try
42+
4143
/**
4244
* Text value representation
4345
*
@@ -171,7 +173,7 @@ class URL(value: Option[String]) extends Text(value){
171173
* RFC2396 (http://www.ietf.org/rfc/rfc2396.txt)
172174
* Default valid protocols are: http, https, ftp.
173175
*/
174-
def isValid: Boolean = value.exists(UrlValidator.getInstance().isValid)
176+
def isValid: Boolean = value.exists(v => UrlValidator.getInstance().isValid(v) && Try(new java.net.URL(v)).isSuccess)
175177
/**
176178
* Verifies if the url is of correct form of "Uniform Resource Identifiers (URI): Generic Syntax"
177179
* RFC2396 (http://www.ietf.org/rfc/rfc2396.txt)

features/src/test/scala/com/salesforce/op/features/types/URLTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class URLTest extends PropSpec with PropertyChecks with TestCommon {
4848
Some("ftp://.codomain"),
4949
Some("https://.codomain"),
5050
Some("//domain.nambia"),
51-
Some("http://\u00ff\u0080\u007f\u0000.com") // scalastyle:off
51+
Some("http://\u00ff\u0080\u007f\u0000.com"), // scalastyle:off
52+
Some("http://specialchars.@.com")
5253
)
5354

5455
val goodOnes = Table("good ones",

0 commit comments

Comments
 (0)