Incorrect links generated within a sub-application

If we generate a link to "~/content/test.js" within an application "Test", VirtualPathUtility.ToAbsolute("~") will return "/Test" so Replace("~/", VirtualPathUtility.ToAbsolute("~")) returns "/Testcontent/test.js".