diff --git a/lib/appconfig.php b/lib/appconfig.php index 3d0d6f34..c33cbe6c 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -457,11 +457,27 @@ public function GetDocumentServerInternalUrl($origin = false) { * @return string */ public function ReplaceDocumentServerUrlToInternal($url) { + // GetDocumentServerInternalUrl() will be the same with GetDocumentServerUrl() if internal url is not specified. $documentServerUrl = $this->GetDocumentServerInternalUrl(); + if (!empty($documentServerUrl)) { $from = $this->GetDocumentServerUrl(); + if (!preg_match("/^https?:\/\//i", $url)){ + // $url is not a complete url. Form it with $from + $parsedUrl = parse_url($from); + + // $url may include VPATH. Judge it to avoid dupe. + // https://github.com/ONLYOFFICE/document-server-proxy/blob/master/apache/proxy-to-virtual-path.conf + $vpath = $parsedUrl["path"]; + if (empty($vpath)){ + $vpath = "/"; + } + $url = $from.preg_filter("#^$vpath#i", "", $url, 1); + } + if (!preg_match("/^https?:\/\//i", $from)) { + // Frontend forbids input incomplete url, so this will never happen? $parsedUrl = parse_url($url); $from = $parsedUrl["scheme"] . "://" . $parsedUrl["host"] . (array_key_exists("port", $parsedUrl) ? (":" . $parsedUrl["port"]) : "") . $from; } diff --git a/lib/documentservice.php b/lib/documentservice.php index 308d1d68..cda97d99 100644 --- a/lib/documentservice.php +++ b/lib/documentservice.php @@ -97,7 +97,13 @@ function GetConvertedUri($document_uri, $from_extension, $to_extension, $documen $isEndConvert = $responceFromConvertService->EndConvert; if ($isEndConvert !== null && strtolower($isEndConvert) === "true") { - return $responceFromConvertService->FileUrl; + $fileUrl = $responceFromConvertService->FileUrl; + if ( !preg_match("/^https?:\/\//i", $fileUrl) ){ + $url = parse_url($document_uri); + $fileUrl = $url["scheme"] . "://" . $url['host'] . (array_key_exists("port", $url) ? (":" . $url["port"]) : "") . $fileUrl ; + } + + return $fileUrl; } return "";