diff --git a/b0esche_cloud/lib/pages/document_viewer.dart b/b0esche_cloud/lib/pages/document_viewer.dart index 005167a..c3693e8 100644 --- a/b0esche_cloud/lib/pages/document_viewer.dart +++ b/b0esche_cloud/lib/pages/document_viewer.dart @@ -404,9 +404,10 @@ class _DocumentViewerModalState extends State { final wopiSession = snapshot.data!; // Build Collabora Online viewer URL with WOPISrc - // Note: Don't double-encode the WOPISrc - Collabora expects the URL as-is + // The WOPISrc must be URL-encoded since it contains special characters (://, ?, =, &) + final encodedWopisrc = Uri.encodeComponent(wopiSession.wopisrc); final collaboraUrl = - 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html?WOPISrc=${wopiSession.wopisrc}'; + 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html?WOPISrc=$encodedWopisrc'; // Use WebView to display Collabora Online return _buildWebView(collaboraUrl); @@ -460,13 +461,9 @@ class _DocumentViewerModalState extends State { ui.platformViewRegistry.registerViewFactory( viewType, (int viewId) { - // Extract the WOPISrc value - final wopisrcValue = collaboraUrl.contains('WOPISrc=') - ? Uri.decodeComponent(collaboraUrl.split('WOPISrc=')[1]) - : ''; - - // Create the iframe + // Create the iframe with the properly encoded Collabora URL final iframe = html.IFrameElement() + ..src = collaboraUrl ..style.border = 'none' ..style.width = '100%' ..style.height = '100%' @@ -476,17 +473,12 @@ class _DocumentViewerModalState extends State { 'allow', 'microphone; camera; usb; autoplay; clipboard-read; clipboard-write', ) - // Remove allow-same-origin and add allow-popups-to-escape-sandbox for better security + // Remove allow-same-origin for security, add allow-popups-to-escape-sandbox ..setAttribute( 'sandbox', 'allow-scripts allow-popups allow-forms allow-pointer-lock allow-presentation allow-modals allow-downloads allow-popups-to-escape-sandbox', ); - // Build the full Collabora URL - final collaboraPath = - 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html'; - iframe.src = '$collaboraPath?WOPISrc=$wopisrcValue'; - return iframe; }, );