From 69cf3289720623bb206e2a65a30333c92d5a8ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Mon, 12 Jan 2026 09:50:41 +0100 Subject: [PATCH] Fix Collabora 400 error by properly URL-encoding WOPISrc parameter - WOPISrc is a full URL that needs URL encoding when passed as query param - Use Uri.encodeComponent() to properly encode the WOPISrc value - Simplify iframe setup to just use the properly constructed URL - This fixes the 400 Bad Request from Collabora when loading documents --- b0esche_cloud/lib/pages/document_viewer.dart | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) 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; }, );