Некоторый необработанный код делает то, что вы хотите, поэтому вы можете пропустить все раздутые библиотеки:
var urlJoin:Function = function(base:String, relative:String):String
{
// See if there is already a protocol on this
if (relative.indexOf("://") != -1)
return relative;
// See if this is protocol-relative
if (relative.indexOf("//") == 0)
{
var protocolIndex:int = base.indexOf("://");
return base.substr(0, protocolIndex+1) + relative;
}
// We need to split the domain and the path for the remaining options
var protocolIndexEnd:int = base.indexOf("://") + 3;
if (base.indexOf("/", protocolIndexEnd) == -1) // append slash if passed only http://bla.com
base += "/";
var endDomainIndex:int = base.indexOf("/", protocolIndexEnd);
var domain:String = base.substr(0, endDomainIndex);
var path:String = base.substr(endDomainIndex);
if (path.lastIndexOf("/") != path.length-1) // trim off any ending file name
path = path.substr(0, path.lastIndexOf("/")+1);
// See if this is site-absolute
if (relative.indexOf("/") == 0)
{
return domain + relative;
}
// See if this is document-relative with ../
while (relative.indexOf("../") == 0)
{
relative = relative.substr(3);
if (path.length > 1)
{
var secondToLastSlashIndex:int = path.substr(0, path.length-1).lastIndexOf("/");
path = path.substr(0, secondToLastSlashIndex+1);
}
}
// Finally, slap on whatever ending is left
return domain + path + relative;
};