lib/scrivito/link_parser.rb in scrivito_sdk-0.70.2 vs lib/scrivito/link_parser.rb in scrivito_sdk-0.71.0.rc1
- old
+ new
@@ -38,10 +38,21 @@
end
private
def application_uri?(uri)
- uri.absolute? && internal_uri?(uri) || uri.relative? && uri.path.present?
+ absolute_uri?(uri) && internal_uri?(uri) || relative_uri?(uri) && uri.path.present?
+ end
+
+ def absolute_uri?(uri)
+ # Ruby's URI parser assumes URLs without a scheme as relativ, while a browser assumes a
+ # schemeless "//scrivito.com" as absolute. Since the URLs are for the browser, we cannot use
+ # Ruby's URI here.
+ uri.to_s =~ /\A([a-z][a-z\d\-+\.]*:|\/\/).*/i
+ end
+
+ def relative_uri?(uri)
+ !absolute_uri?(uri)
end
def internal_uri?(uri)
if uri.port.present?
uri.host == @host && uri.port == Integer(@port)