File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
androidTest/java/com/duckduckgo/app/browser
main/java/com/duckduckgo/app/browser Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -127,4 +127,16 @@ class SpecialUrlDetectorImplTest {
127
127
val type = testee.determineType(" smsto:123-555-12323" ) as Sms
128
128
assertEquals(" 123-555-12323" , type.telephoneNumber)
129
129
}
130
+
131
+ @Test
132
+ fun whenUrlIsCustomUriSchemeThenIntentTypeDetected () {
133
+ val type = testee.determineType(" myapp:foo bar" ) as IntentType
134
+ assertEquals(" myapp:foo bar" , type.url)
135
+ }
136
+
137
+ @Test
138
+ fun whenUrlIsParametrizedQueryThenSearchQueryTypeDetected () {
139
+ val type = testee.determineType(" foo site:duckduckgo.com" ) as SearchQuery
140
+ assertEquals(" foo site:duckduckgo.com" , type.query)
141
+ }
130
142
}
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ class SpecialUrlDetectorImpl : SpecialUrlDetector {
52
52
HTTP_SCHEME , HTTPS_SCHEME , DATA_SCHEME -> UrlType .Web (uriString)
53
53
ABOUT_SCHEME -> UrlType .Unknown (uriString)
54
54
null -> UrlType .SearchQuery (uriString)
55
- else -> buildIntent( uriString)
55
+ else -> checkForIntent(scheme, uriString)
56
56
}
57
57
}
58
58
@@ -66,6 +66,15 @@ class SpecialUrlDetectorImpl : SpecialUrlDetector {
66
66
67
67
private fun buildSmsTo (uriString : String ) = UrlType .Sms (uriString.removePrefix(" $SMSTO_SCHEME :" ))
68
68
69
+ private fun checkForIntent (scheme : String , uriString : String ): UrlType {
70
+ val validUriSchemeRegex = Regex (" [a-z][a-zA-Z\\ d+.-]+" )
71
+ if (scheme.matches(validUriSchemeRegex)){
72
+ return buildIntent(uriString)
73
+ }
74
+
75
+ return UrlType .SearchQuery (uriString)
76
+ }
77
+
69
78
private fun buildIntent (uriString : String ): UrlType {
70
79
return try {
71
80
val intent = Intent .parseUri(uriString, 0 )
You can’t perform that action at this time.
0 commit comments