Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
69648819
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
69648819
编写于
3月 02, 2016
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23649 from maclover7/fix-22675
Accept channel identifiers with no backslashes/escaping
上级
fc1b32f8
45635098
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
27 addition
and
8 deletion
+27
-8
actioncable/CHANGELOG.md
actioncable/CHANGELOG.md
+5
-0
actioncable/lib/action_cable/connection/subscriptions.rb
actioncable/lib/action_cable/connection/subscriptions.rb
+19
-6
actioncable/test/connection/subscriptions_test.rb
actioncable/test/connection/subscriptions_test.rb
+2
-2
actioncable/test/test_helper.rb
actioncable/test/test_helper.rb
+1
-0
未找到文件。
actioncable/CHANGELOG.md
浏览文件 @
69648819
*
Allow channel identifiers with no backslahes/escaping to be accepted
by the subscription storer.
*Jon Moss*
*
Safely support autoloading and class unloading, by preventing concurrent
loads, and disconnecting all cables during reload.
...
...
actioncable/lib/action_cable/connection/subscriptions.rb
浏览文件 @
69648819
...
...
@@ -23,13 +23,13 @@ def execute_command(data)
end
def
add
(
data
)
id_
key
=
data
[
'identifier'
]
id
_options
=
ActiveSupport
::
JSON
.
decode
(
id_key
).
with_indifferent_access
id_
options
=
decode_hash
(
data
[
'identifier'
])
id
entifier
=
normalize_identifier
(
id_options
)
subscription_klass
=
connection
.
server
.
channel_classes
[
id_options
[
:channel
]]
if
subscription_klass
subscriptions
[
id
_key
]
||=
subscription_klass
.
new
(
connection
,
id_key
,
id_options
)
subscriptions
[
id
entifier
]
||=
subscription_klass
.
new
(
connection
,
identifier
,
id_options
)
else
logger
.
error
"Subscription class not found (
#{
data
.
inspect
}
)"
end
...
...
@@ -37,7 +37,7 @@ def add(data)
def
remove
(
data
)
logger
.
info
"Unsubscribing from channel:
#{
data
[
'identifier'
]
}
"
remove_subscription
subscriptions
[
data
[
'identifier'
]
]
remove_subscription
subscriptions
[
normalize_identifier
(
data
[
'identifier'
])
]
end
def
remove_subscription
(
subscription
)
...
...
@@ -46,7 +46,7 @@ def remove_subscription(subscription)
end
def
perform_action
(
data
)
find
(
data
).
perform_action
ActiveSupport
::
JSON
.
decode
(
data
[
'data'
]
)
find
(
data
).
perform_action
(
decode_hash
(
data
[
'data'
])
)
end
def
identifiers
...
...
@@ -63,8 +63,21 @@ def unsubscribe_from_all
private
delegate
:logger
,
to: :connection
def
normalize_identifier
(
identifier
)
identifier
=
ActiveSupport
::
JSON
.
encode
(
identifier
)
if
identifier
.
is_a?
(
Hash
)
identifier
end
# If `data` is a Hash, this means that the original JSON
# sent by the client had no backslashes in it, and does
# not need to be decoded again.
def
decode_hash
(
data
)
data
=
ActiveSupport
::
JSON
.
decode
(
data
)
unless
data
.
is_a?
(
Hash
)
data
.
with_indifferent_access
end
def
find
(
data
)
if
subscription
=
subscriptions
[
data
[
'identifier'
]
]
if
subscription
=
subscriptions
[
normalize_identifier
(
data
[
'identifier'
])
]
subscription
else
raise
"Unable to find subscription with identifier:
#{
data
[
'identifier'
]
}
"
...
...
actioncable/test/connection/subscriptions_test.rb
浏览文件 @
69648819
...
...
@@ -82,13 +82,13 @@ def speak(data)
end
end
test
"unsubscrib from all"
do
test
"unsubscrib
e
from all"
do
run_in_eventmachine
do
setup_connection
channel1
=
subscribe_to_chat_channel
channel2_id
=
ActiveSupport
::
JSON
.
encode
(
id:
2
,
channel:
'ActionCable::Connection::SubscriptionsTest::ChatChannel'
)
channel2_id
=
ActiveSupport
::
JSON
.
encode
(
{
id:
2
,
channel:
'ActionCable::Connection::SubscriptionsTest::ChatChannel'
}
)
channel2
=
subscribe_to_chat_channel
(
channel2_id
)
channel1
.
expects
(
:unsubscribe_from_channel
)
...
...
actioncable/test/test_helper.rb
浏览文件 @
69648819
...
...
@@ -6,6 +6,7 @@
require
'mocha/setup'
require
'rack/mock'
require
'active_support/core_ext/hash/indifferent_access'
# Require all the stubs and models
Dir
[
File
.
dirname
(
__FILE__
)
+
'/stubs/*.rb'
].
each
{
|
file
|
require
file
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录