[PATCH v4 compass-ci] /src/lib/web_backend.rb: fix "/compare_candidates" tbox_group regex bug

Error Flow: 1. /\d+$/ will be matched, such as "xxx123". 2. `index = "xxx123".index('--') || "xxx123".rindex('-')` - index equal nil. 3. `r = r[0, nil]` - raise a TypeError. Solution: Fill a couple brackets, so will just 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 -- 2.23.0

On Wed, Oct 21, 2020 at 10:46:29AM +0800, Zhang Yuhang wrote:
Error Flow: 1. /\d+$/ will be matched, such as "xxx123".
Do you mean "xxx123" is an error example because it doesn't have '--' or '-' within? Then you can say such as "xxx123", which has no '--' or '-' in it. That would be easy to understand. Thanks, Yuanchao
2. `index = "xxx123".index('--') || "xxx123".rindex('-')` - index equal nil.
3. `r = r[0, nil]` - raise a TypeError.
Solution: Fill a couple brackets, so will just 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 -- 2.23.0

On Wed, Oct 21, 2020 at 11:22:40AM +0800, Li Yuanchao wrote:
On Wed, Oct 21, 2020 at 10:46:29AM +0800, Zhang Yuhang wrote:
Error Flow: 1. /\d+$/ will be matched, such as "xxx123".
Do you mean "xxx123" is an error example because it doesn't have '--' or '-' within? Then you can say
such as "xxx123", which has no '--' or '-' in it.
That would be easy to understand.
Thanks, Yuanchao
OK, Thanks. Thanks, Zhang Yuhang
2. `index = "xxx123".index('--') || "xxx123".rindex('-')` - index equal nil.
3. `r = r[0, nil]` - raise a TypeError.
Solution: Fill a couple brackets, so will just 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 -- 2.23.0

On Wed, Oct 21, 2020 at 11:22:40AM +0800, Li Yuanchao wrote:
On Wed, Oct 21, 2020 at 10:46:29AM +0800, Zhang Yuhang wrote:
Error Flow: 1. /\d+$/ will be matched, such as "xxx123".
Do you mean "xxx123" is an error example because it doesn't have '--' or '-' within? Then you can say
such as "xxx123", which has no '--' or '-' in it.
That would be easy to understand.
Thanks, Yuanchao
Because /^vm-.*-\d\w*-([a-zA-Z]+)|(\d+)$)/ mean for /^vm-.*-\d\w*-([a-zA-Z]+)/ or /\d+)$/ It will match /\d+$/, and match such as "xxx123". That is the error point. Not because of it doesn't have '--' or '-' within. It doesn't have '--' or '-' within, which is the result of fault regex. :) Thanks, Zhang Yuhang
participants (2)
-
Li Yuanchao
-
Zhang Yuhang