Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
d72f8db0
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d72f8db0
编写于
5月 27, 2012
作者:
R
randx
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'fix_encoding' of
https://github.com/brodock/gitlabhq
into brodock-fix_encoding
Conflicts: lib/gitlab/encode.rb
上级
d29ec9d7
11f90ae4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
29 addition
and
13 deletion
+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
未找到文件。
app/controllers/refs_controller.rb
浏览文件 @
d72f8db0
class
RefsController
<
ApplicationController
include
Gitlabhq
::
Encode
before_filter
:project
# Authorize
...
...
@@ -43,23 +44,26 @@ class RefsController < ApplicationController
no_cache_headers
end
end
rescue
return
render_404
end
def
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
(
@tree
.
data
,
:type
=>
@tree
.
text?
?
"text/plain"
:
@tree
.
mime_type
,
:type
=>
mime_type
,
:disposition
=>
'inline'
,
:filename
=>
@tree
.
name
)
else
head
(
404
)
end
rescue
return
render_404
end
def
blame
...
...
app/views/commits/_commit.html.haml
浏览文件 @
d72f8db0
...
...
@@ -8,7 +8,7 @@
%strong
.cgray
=
commit
.
author_name
–
=
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
=
time_ago_in_words
(
commit
.
committed_date
)
...
...
app/views/refs/_tree.html.haml
浏览文件 @
d72f8db0
...
...
@@ -42,9 +42,9 @@
.readme
-
if
content
.
name
=~
/\.(md|markdown)$/i
=
preserve
do
=
markdown
(
content
.
data
.
force_encoding
(
'UTF-8'
)
)
=
markdown
(
content
.
data
.
detect_encoding!
)
-
else
=
simple_format
(
content
.
data
.
force_encoding
(
'UTF-8'
)
)
=
simple_format
(
content
.
data
.
detect_encoding!
)
-
if
params
[
:path
]
-
history_path
=
tree_file_project_ref_path
(
@project
,
@ref
,
params
[
:path
])
...
...
app/views/refs/_tree_file.html.haml
浏览文件 @
d72f8db0
...
...
@@ -13,7 +13,7 @@
#tree-readme-holder
.readme
=
preserve
do
=
markdown
(
file
.
data
.
force_encoding
(
'UTF-8'
)
)
=
markdown
(
file
.
data
.
detect_encoding!
)
-
else
.view_file_content
-
unless
file
.
empty?
...
...
lib/gitlab/encode.rb
浏览文件 @
d72f8db0
# Patch Strings to enable detect_encoding! on views
require
'charlock_holmes/string'
module
Gitlab
module
Encode
extend
self
...
...
@@ -5,16 +7,26 @@ module Gitlab
def
utf8
message
return
nil
unless
message
hash
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
rescue
{}
if
hash
[
:encoding
]
CharlockHolmes
::
Converter
.
convert
(
message
,
hash
[
:encoding
],
'UTF-8'
)
detect
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
rescue
{}
# 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
message
end
.
force_encoding
(
"utf-8"
)
# Prevent app from crash cause of
# encoding errors
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录