Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8d89fb21
Commit
8d89fb21
authored
May 05, 2021
by
Gary Holtz
Committed by
Alex Kalderimis
May 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Configurable setting for max text size for highlighting
parent
6d4e4385
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
4 deletions
+18
-4
changelogs/unreleased/gmh-ensure-highlighting-limits-are-configurable-and-documented.yml
...e-highlighting-limits-are-configurable-and-documented.yml
+5
-0
config/gitlab.yml.example
config/gitlab.yml.example
+4
-0
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+1
-0
lib/gitlab/highlight.rb
lib/gitlab/highlight.rb
+5
-2
spec/lib/gitlab/highlight_spec.rb
spec/lib/gitlab/highlight_spec.rb
+3
-2
No files found.
changelogs/unreleased/gmh-ensure-highlighting-limits-are-configurable-and-documented.yml
0 → 100644
View file @
8d89fb21
---
title
:
Ensure highlighting limits are documented, configurable, and monitorable
merge_request
:
60445
author
:
type
:
added
config/gitlab.yml.example
View file @
8d89fb21
...
...
@@ -1270,6 +1270,10 @@ production: &base
# matomo_site_id: '_your_matomo_site_id'
# matomo_disable_cookies: false
## Maximum file size for syntax highlighting
## https://docs.gitlab.com/ee/user/project/highlighting.html
# maximum_text_highlight_size_kilobytes: 512
rack_attack:
git_basic_auth:
# Rack Attack IP banning enabled
...
...
config/initializers/1_settings.rb
View file @
8d89fb21
...
...
@@ -856,6 +856,7 @@ Settings['extra'] ||= Settingslogic.new({})
Settings
.
extra
[
'matomo_site_id'
]
||=
Settings
.
extra
[
'piwik_site_id'
]
if
Settings
.
extra
[
'piwik_site_id'
].
present?
Settings
.
extra
[
'matomo_url'
]
||=
Settings
.
extra
[
'piwik_url'
]
if
Settings
.
extra
[
'piwik_url'
].
present?
Settings
.
extra
[
'matomo_disable_cookies'
]
=
false
if
Settings
.
extra
[
'matomo_disable_cookies'
].
nil?
Settings
.
extra
[
'maximum_text_highlight_size_kilobytes'
]
=
Settings
.
extra
.
fetch
(
'maximum_text_highlight_size_kilobytes'
,
512
).
kilobytes
#
# Rack::Attack settings
...
...
lib/gitlab/highlight.rb
View file @
8d89fb21
...
...
@@ -4,7 +4,6 @@ module Gitlab
class
Highlight
TIMEOUT_BACKGROUND
=
30
.
seconds
TIMEOUT_FOREGROUND
=
1.5
.
seconds
MAXIMUM_TEXT_HIGHLIGHT_SIZE
=
512
.
kilobytes
def
self
.
highlight
(
blob_name
,
blob_content
,
language:
nil
,
plain:
false
)
new
(
blob_name
,
blob_content
,
language:
language
)
...
...
@@ -23,7 +22,7 @@ module Gitlab
def
highlight
(
text
,
continue:
false
,
plain:
false
,
context:
{})
@context
=
context
plain
||=
text
.
length
>
MAXIMUM_TEXT_HIGHLIGHT_SIZE
plain
||=
text
.
length
>
maximum_text_highlight_size
highlighted_text
=
highlight_text
(
text
,
continue:
continue
,
plain:
plain
)
highlighted_text
=
link_dependencies
(
text
,
highlighted_text
)
if
blob_name
...
...
@@ -78,5 +77,9 @@ module Gitlab
def
link_dependencies
(
text
,
highlighted_text
)
Gitlab
::
DependencyLinker
.
link
(
blob_name
,
text
,
highlighted_text
)
end
def
maximum_text_highlight_size
Gitlab
.
config
.
extra
[
'maximum_text_highlight_size_kilobytes'
]
end
end
end
spec/lib/gitlab/highlight_spec.rb
View file @
8d89fb21
...
...
@@ -47,8 +47,9 @@ RSpec.describe Gitlab::Highlight do
end
it
'returns plain version for long content'
do
stub_const
(
'Gitlab::Highlight::MAXIMUM_TEXT_HIGHLIGHT_SIZE'
,
1
)
result
=
described_class
.
highlight
(
file_name
,
content
)
stub_config
(
extra:
{
'maximum_text_highlight_size_kilobytes'
=>
0.0001
}
)
# 1.024 bytes
result
=
described_class
.
highlight
(
file_name
,
content
)
# content is 44 bytes
expect
(
result
).
to
eq
(
%[<span id="LC1" class="line" lang="">(make-pathname :defaults name</span>\n<span id="LC2" class="line" lang="">:type "assem")</span>]
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment