From 9088bba1f4b9f3d99210998145b530a8c8d839cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Sch=C3=A4fer?= <felix@plan.io>
Date: Thu, 3 Dec 2026 11:04:03 +0800
Subject: [PATCH] Do not render markup of repository files too large to display

@content is nil for files larger than file_max_size_displayed. The
repository browser still rendered Markdown and Textile files as markup,
which raised an error for such files.
---
 app/views/repositories/entry.html.erb            | 12 +++++++-----
 .../repositories_subversion_controller_test.rb   | 16 ++++++++++++++++
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/app/views/repositories/entry.html.erb b/app/views/repositories/entry.html.erb
index 66c2154b9..84951f026 100644
--- a/app/views/repositories/entry.html.erb
+++ b/app/views/repositories/entry.html.erb
@@ -12,12 +12,14 @@
   <%= render :partial => 'common/image', :locals => {:path => @raw_url, :alt => @path} %>
 <% elsif Redmine::MimeType.of(@path) == 'application/pdf' %>
   <%= render :partial => 'common/pdf', :locals => {:path => @raw_url} %>
-<% elsif Redmine::MimeType.of(@path) == 'text/x-textile' %>
-  <%= render :partial => 'common/markup', :locals => {:markup_text_formatting => 'textile', :markup_text => @content} %>
-<% elsif Redmine::MimeType.of(@path) == 'text/markdown' %>
-  <%= render :partial => 'common/markup', :locals => {:markup_text_formatting => 'common_mark', :markup_text => @content} %>
 <% elsif @content %>
-  <%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
+  <% if Redmine::MimeType.of(@path) == 'text/x-textile' %>
+    <%= render :partial => 'common/markup', :locals => {:markup_text_formatting => 'textile', :markup_text => @content} %>
+  <% elsif Redmine::MimeType.of(@path) == 'text/markdown' %>
+    <%= render :partial => 'common/markup', :locals => {:markup_text_formatting => 'common_mark', :markup_text => @content} %>
+  <% else %>
+    <%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
+  <% end %>
 <% else %>
   <% kind = if Redmine::MimeType.is_type?('video', @path)
        'video'
diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb
index 0a430317f..e21a6ef40 100644
--- a/test/functional/repositories_subversion_controller_test.rb
+++ b/test/functional/repositories_subversion_controller_test.rb
@@ -254,6 +254,22 @@ class RepositoriesSubversionControllerTest < Redmine::RepositoryControllerTest
       end
     end
 
+    def test_entry_should_show_other_for_markup_if_too_big
+      with_settings :file_max_size_displayed => 0 do
+        get(
+          :entry,
+          :params => {
+            :id => PRJ_ID,
+            :repository_id => @repository.id,
+            :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'testfile.md'])[:param]
+          }
+        )
+        assert_response :success
+        assert_select 'div.wiki', 0
+        assert_select 'p.nodata'
+      end
+    end
+
     def test_entry_should_display_images
       get(
         :entry,
-- 
2.56.1

