swf property doesn't correctly handle protocol relative urls
submitteddenied opened this issue · comments
Using a protocol relative url to load the FlashTransport swf causes the resolveUrl function to return a bad URL.
Example:
Given //assets.example.com/path/to/swf.swf
, resolveUrl returns http://localhost//assets.example.com/path/to/swf.swf
This is because the regular expression inside the if statement (!url.match(/^(http||https):\/\//)
) checks explicitly for http
or https
, and doesn't handle the url starting with //
@oyvindkinsey We have the exact same problem, also caused by resolveUrl
. However the solution proposed by @EmJay1988 doesnt work for us. I think the easiest way to solve it is to add a special test case for protocol relative URLs, like this :
// If the url is already a valid absolute URL we do nothing
if (!url.match(/^(http||https):\/\//)) {
// If the url is a protocol relative URL, we simply append the protocol to it
if (url.match(/^\/\//)) {
url = location.protocol + url;
} else {
// If this is a relative path
var path = (url.substring(0, 1) === "/") ? "" : location.pathname;
if (path.substring(path.length - 1) !== "/") {
path = path.substring(0, path.lastIndexOf("/") + 1);
}
url = location.protocol + "//" + location.host + path + url;
}
}
I would like to hear your thoughts about this !
I have added my colleagues to this discussion: @czzarr @charlesmigli