网页连接主机 js regx bug #292

Open
liuyangc3 opened this Issue Sep 1, 2016 · 1 comment

Projects

None yet

2 participants

@liuyangc3
liuyangc3 commented Sep 1, 2016 edited

webterminal.js line 16 :

var endpoint = protocol + 
document.URL.match(RegExp('//(.*?)/'))[1] + '/ws/terminal' + document.URL.match(/(\?.*)/);

最后 这个 document.URL.match(/(\?.*)/),如果 url 是http://jumpserver.com/terminal/?id=1&role=admin
由于正则使用了分组去匹配问号后的所有字符,那么 match 返回的结果是数组
["?id=1&role=admin", "?id=1&role=admin"]

这就回导致拼接出来的 endpoint 变成这样

ws://jumpserver.com/ws/terminal?id=1&role=admin,?id=1&role=admin

而期望的结果应该是

ws://jumpserver.com/ws/terminal?id=1&role=admin

所以document.URL.match(/(\?.*)/)

里的正则表达式应该去掉分组,变为 document.URL.match(/\?.*/)

@ibuler
Member
ibuler commented Sep 1, 2016

是有这个问题,你提个PR吧

@liuyangc3 liuyangc3 referenced this issue Sep 1, 2016
Open

fix #292 #293

@jiaxiangkong jiaxiangkong added a commit that referenced this issue Nov 9, 2016
@jiaxiangkong jiaxiangkong 网页连接主机 js regx bug #292
ws://jumpserver.com/ws/terminal?id=1&role=admin,?id=1&role=admin
而期望的结果应该是ws://jumpserver.com/ws/terminal?id=1&role=admin
所以document.URL.match(/(\?.*)/)里的正则表达式应该去掉分组,变为 document.URL.match(/\?.*/)
5474082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment