 }
 
 func urlJoin(_ lhs: String, _ rhs: String) -> String {
-  if rhs.hasPrefix("#") {
-    return lhs + rhs
+  if lhs.isEmpty {
+    return rhs
   }
-  return rhs
+
+  if rhs.isEmpty {
+    return lhs
+  }
+
+  return URL(string: rhs, relativeTo: URL(string: lhs)!)!.absoluteString
 }
 
 func urlNormalise(_ value: String) -> String {

            continue
          }
        }
      }

      return nil

    return nil
  }

  func resolve(document: [String: Any], fragment: String) -> Any? {
    guard !fragment.isEmpty else {
      return document
    }
