Skip to content

Commit 89cde08

Browse files
committed
Merge from snowplow/master.
2 parents de1c775 + 30b976b commit 89cde08

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ We welcome contributions to referer-parser:
171171
2. **Ports of referer-parser to other languages** - we welcome ports of referer-parser to new programming languages (e.g. JavaScript, PHP, Go, Haskell)
172172
3. **Bug fixes, feature requests etc** - much appreciated!
173173

174+
**Please sign the [Snowplow CLA] [cla] before making pull requests.**
175+
174176
## Support
175177

176178
General support for referer-parser is handled by the team at Snowplow Analytics Ltd.
@@ -211,3 +213,4 @@ The .NET port is copyright 2013 [iPerform Software] [iperform] and is available
211213

212214
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
213215
[gpl-license]: http://www.gnu.org/licenses/gpl-3.0.html
216+
[cla]: https://github.com/snowplow/snowplow/wiki/CLA

java-scala/project/BuildSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object BuildSettings {
2222
// Basic settings for our app
2323
lazy val basicSettings = Seq[Setting[_]](
2424
organization := "com.snowplowanalytics",
25-
version := "0.1.0",
25+
version := "0.1.1",
2626
description := "Library for extracting marketing attribution data from referer URLs",
2727
scalaVersion := "2.9.1",
2828
scalacOptions := Seq("-deprecation", "-encoding", "utf8"),

java-scala/src/main/java/com/snowplowanalytics/refererparser/Parser.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,36 @@ public Referer parse(String refererUri, String pageHost) throws URISyntaxExcepti
106106

107107
public Referer parse(URI refererUri, String pageHost) {
108108

109+
// Have to declare up here without `final` due to try/catch scoping
110+
String scheme;
111+
String host;
112+
String path;
113+
109114
// null unless we have a valid http: or https: URI
110115
if (refererUri == null) return null;
111-
final String scheme = refererUri.getScheme();
116+
117+
try {
118+
scheme = refererUri.getScheme();
119+
host = refererUri.getHost();
120+
path = refererUri.getPath();
121+
} catch(Exception e) { // Not a valid URL
122+
return null;
123+
}
124+
112125
if (scheme == null || (!scheme.equals("http") && !scheme.equals("https"))) return null;
113126

114127
// Internal link if hosts match exactly
115128
// TODO: would also be nice to:
116129
// 1. Support a list of other hosts which count as internal
117130
// 2. Have an algo for stripping subdomains before checking match
118-
if (refererUri.getHost().equals(pageHost)) return new Referer(Medium.INTERNAL, null, null);
131+
if (host == null) return null; // Not a valid URL
132+
if (host.equals(pageHost)) return new Referer(Medium.INTERNAL, null, null);
119133

120134
// Try to lookup our referer. First check with paths, then without.
121135
// This is the safest way of handling lookups
122-
RefererLookup referer = lookupReferer(refererUri.getHost(), refererUri.getPath(), true);
136+
RefererLookup referer = lookupReferer(host, path, true);
123137
if (referer == null) {
124-
referer = lookupReferer(refererUri.getHost(), refererUri.getPath(), false);
138+
referer = lookupReferer(host, path, false);
125139
}
126140

127141
if (referer == null) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2012-2013 Snowplow Analytics Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.snowplowanalytics.refererparser.scala
18+
19+
// Java
20+
import java.net.URI
21+
22+
// Specs2
23+
import org.specs2.mutable.Specification
24+
25+
class CorruptedRefererUriTest extends Specification {
26+
27+
// Our data
28+
val refererUri = "http://bigcommerce%20wordpress%20plugin/"
29+
val pageUri = null.asInstanceOf[String]
30+
31+
"A corrupted referer URI" should {
32+
"return None, not throw an Exception" in {
33+
Parser.parse(refererUri,pageUri) must beNone
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)