Info: "/compare_canditates" error, due to fault regular expression
Detail: Miss a couple brackets, so will match /\d+$/.
Error Flow: 1. like "xxx123" will be matched 2. index = "xxx123".index('--') || "xxx123".rindex('-') 3. index equal "nil" 4. r = r[0, nil] will raise an error "TypeError (no implicit conversion from nil to integer)"
Solution: Fill a couple brackets, so will match "vm-abc-0abc-abc" or "vm-abc-0abc-012".
Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com --- src/lib/web_backend.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 48cfadb..fda01ca 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -47,7 +47,7 @@ end def filter_tbox_group(es_result) result = Set.new es_result.each do |r| - if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-([a-zA-Z]+)|(\d+)$)/ + if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/ index = r.index('--') || r.rindex('-') r = r[0, index] end
On Wed, Oct 21, 2020 at 10:15:03AM +0800, Zhang Yuhang wrote:
Info: "/compare_canditates" error, due to fault regular expression
Detail:
说 detail 有啥用? 到底是啥嘛? Problem?
Miss a couple brackets, so will match /\d+$/.
Error Flow:
- like "xxx123" will be matched
- index = "xxx123".index('--') || "xxx123".rindex('-')
- index equal "nil"
- r = r[0, nil] will raise an error "TypeError (no implicit conversion from nil to integer)"
Good.
Solution: Fill a couple brackets, so will match "vm-abc-0abc-abc" or "vm-abc-0abc-012".
Thanks, Fengguang
Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com
src/lib/web_backend.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 48cfadb..fda01ca 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -47,7 +47,7 @@ end def filter_tbox_group(es_result) result = Set.new es_result.each do |r|
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-([a-zA-Z]+)|(\d+)$)/
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/ index = r.index('--') || r.rindex('-') r = r[0, index] end
-- 2.23.0
On Wed, Oct 21, 2020 at 10:15:03AM +0800, Zhang Yuhang wrote:
Info: "/compare_canditates" error, due to fault regular expression
Detail: Miss a couple brackets, so will match /\d+$/.
Error Flow:
- like "xxx123" will be matched
- index = "xxx123".index('--') || "xxx123".rindex('-')
- index equal "nil"
- r = r[0, nil] will raise an error "TypeError (no implicit conversion from nil to integer)"
Solution: Fill a couple brackets, so will match "vm-abc-0abc-abc" or "vm-abc-0abc-012".
Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com
src/lib/web_backend.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 48cfadb..fda01ca 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -47,7 +47,7 @@ end def filter_tbox_group(es_result) result = Set.new es_result.each do |r|
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-([a-zA-Z]+)|(\d+)$)/
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/
some comments should be provided to better understand regular expressions. Thanks, Liushaofei
index = r.index('--') || r.rindex('-') r = r[0, index] end
-- 2.23.0
On Wed, Oct 21, 2020 at 04:36:36PM +0800, Liu Shaofei wrote:
On Wed, Oct 21, 2020 at 10:15:03AM +0800, Zhang Yuhang wrote:
Info: "/compare_canditates" error, due to fault regular expression
Detail: Miss a couple brackets, so will match /\d+$/.
Error Flow:
- like "xxx123" will be matched
- index = "xxx123".index('--') || "xxx123".rindex('-')
- index equal "nil"
- r = r[0, nil] will raise an error "TypeError (no implicit conversion from nil to integer)"
Solution: Fill a couple brackets, so will match "vm-abc-0abc-abc" or "vm-abc-0abc-012".
Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com
src/lib/web_backend.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lib/web_backend.rb b/src/lib/web_backend.rb index 48cfadb..fda01ca 100644 --- a/src/lib/web_backend.rb +++ b/src/lib/web_backend.rb @@ -47,7 +47,7 @@ end def filter_tbox_group(es_result) result = Set.new es_result.each do |r|
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-([a-zA-Z]+)|(\d+)$)/
- if r =~ /(^.+--.+$)|(^vm-.*-\d\w*-(([a-zA-Z]+)|(\d+))$)/
some comments should be provided to better understand regular expressions. Thanks, Liushaofei
Yes, I provided comments on the funtion header.
Thanks, Zhang Yuhang
index = r.index('--') || r.rindex('-') r = r[0, index] end
-- 2.23.0