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
d72f8db0
Commit
d72f8db0
authored
May 27, 2012
by
randx
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix_encoding' of
https://github.com/brodock/gitlabhq
into brodock-fix_encoding
Conflicts: lib/gitlab/encode.rb
parents
d29ec9d7
11f90ae4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
13 deletions
+29
-13
app/controllers/refs_controller.rb
app/controllers/refs_controller.rb
+9
-5
app/views/commits/_commit.html.haml
app/views/commits/_commit.html.haml
+1
-1
app/views/refs/_tree.html.haml
app/views/refs/_tree.html.haml
+2
-2
app/views/refs/_tree_file.html.haml
app/views/refs/_tree_file.html.haml
+1
-1
lib/gitlab/encode.rb
lib/gitlab/encode.rb
+16
-4
No files found.
app/controllers/refs_controller.rb
View file @
d72f8db0
class
RefsController
<
ApplicationController
class
RefsController
<
ApplicationController
include
Gitlabhq
::
Encode
before_filter
:project
before_filter
:project
# Authorize
# Authorize
...
@@ -43,23 +44,26 @@ class RefsController < ApplicationController
...
@@ -43,23 +44,26 @@ class RefsController < ApplicationController
no_cache_headers
no_cache_headers
end
end
end
end
rescue
return
render_404
end
end
def
blob
def
blob
if
@tree
.
is_blob?
if
@tree
.
is_blob?
if
@tree
.
text?
encoding
=
detect_encoding
(
@tree
.
data
)
mime_type
=
encoding
?
"text/plain; charset=
#{
encoding
}
"
:
"text/plain"
else
mime_type
=
@tree
.
mime_type
end
send_data
(
send_data
(
@tree
.
data
,
@tree
.
data
,
:type
=>
@tree
.
text?
?
"text/plain"
:
@tree
.
mime_type
,
:type
=>
mime_type
,
:disposition
=>
'inline'
,
:disposition
=>
'inline'
,
:filename
=>
@tree
.
name
:filename
=>
@tree
.
name
)
)
else
else
head
(
404
)
head
(
404
)
end
end
rescue
return
render_404
end
end
def
blame
def
blame
...
...
app/views/commits/_commit.html.haml
View file @
d72f8db0
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
%strong
.cgray
=
commit
.
author_name
%strong
.cgray
=
commit
.
author_name
–
–
=
image_tag
gravatar_icon
(
commit
.
author_email
),
:class
=>
"avatar"
,
:width
=>
16
=
image_tag
gravatar_icon
(
commit
.
author_email
),
:class
=>
"avatar"
,
:width
=>
16
%span
.row_title
=
truncate
(
commit
.
safe_message
,
:length
=>
50
)
rescue
"--broken encoding"
%span
.row_title
=
truncate
(
commit
.
safe_message
,
:length
=>
50
)
%span
.right.cgray
%span
.right.cgray
=
time_ago_in_words
(
commit
.
committed_date
)
=
time_ago_in_words
(
commit
.
committed_date
)
...
...
app/views/refs/_tree.html.haml
View file @
d72f8db0
...
@@ -42,9 +42,9 @@
...
@@ -42,9 +42,9 @@
.readme
.readme
-
if
content
.
name
=~
/\.(md|markdown)$/i
-
if
content
.
name
=~
/\.(md|markdown)$/i
=
preserve
do
=
preserve
do
=
markdown
(
content
.
data
.
force_encoding
(
'UTF-8'
)
)
=
markdown
(
content
.
data
.
detect_encoding!
)
-
else
-
else
=
simple_format
(
content
.
data
.
force_encoding
(
'UTF-8'
)
)
=
simple_format
(
content
.
data
.
detect_encoding!
)
-
if
params
[
:path
]
-
if
params
[
:path
]
-
history_path
=
tree_file_project_ref_path
(
@project
,
@ref
,
params
[
:path
])
-
history_path
=
tree_file_project_ref_path
(
@project
,
@ref
,
params
[
:path
])
...
...
app/views/refs/_tree_file.html.haml
View file @
d72f8db0
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#tree-readme-holder
#tree-readme-holder
.readme
.readme
=
preserve
do
=
preserve
do
=
markdown
(
file
.
data
.
force_encoding
(
'UTF-8'
)
)
=
markdown
(
file
.
data
.
detect_encoding!
)
-
else
-
else
.view_file_content
.view_file_content
-
unless
file
.
empty?
-
unless
file
.
empty?
...
...
lib/gitlab/encode.rb
View file @
d72f8db0
# Patch Strings to enable detect_encoding! on views
require
'charlock_holmes/string'
module
Gitlab
module
Gitlab
module
Encode
module
Encode
extend
self
extend
self
...
@@ -5,16 +7,26 @@ module Gitlab
...
@@ -5,16 +7,26 @@ module Gitlab
def
utf8
message
def
utf8
message
return
nil
unless
message
return
nil
unless
message
hash
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
rescue
{}
detect
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
rescue
{}
if
hash
[
:encoding
]
CharlockHolmes
::
Converter
.
convert
(
message
,
hash
[
:encoding
],
'UTF-8'
)
# It's better to default to UTF-8 as sometimes it's wrongly detected as another charset
if
detect
[
:encoding
]
&&
detect
[
:confidence
]
==
100
CharlockHolmes
::
Converter
.
convert
(
message
,
detect
[
:encoding
],
'UTF-8'
)
else
else
message
message
end
.
force_encoding
(
"utf-8"
)
end
.
force_encoding
(
"utf-8"
)
# Prevent app from crash cause of
# Prevent app from crash cause of
# encoding errors
# encoding errors
rescue
rescue
""
"--broken encoding:
#{
encoding
}
"
end
def
detect_encoding
message
return
nil
unless
message
hash
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
rescue
{}
return
hash
[
:encoding
]
?
hash
[
:encoding
]
:
nil
end
end
end
end
end
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