Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1478b0d

Browse filesBrowse files
committed
Adding validation for tag expression
1 parent adbc76e commit 1478b0d
Copy full SHA for 1478b0d

File tree

5 files changed

+95
-6
lines changed
Filter options

5 files changed

+95
-6
lines changed

‎source/api/ut_runner.pkb

Copy file name to clipboardExpand all lines: source/api/ut_runner.pkb
+2-5
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,10 @@ create or replace package body ut_runner is
9595
ut_event_manager.trigger_event(ut_event_manager.gc_initialize);
9696
ut_event_manager.trigger_event(ut_event_manager.gc_debug, ut_run_info());
9797

98-
--TODO:Verify tag tag expression is valid
99-
/*
100-
if regexp_like(l_tags,'[&|]{2,}|[!-]{2,}|[!-][&|]|[^-&|!,]+[-!]|[-!|&][)]')
101-
or (regexp_count(l_tags,'\(') <> regexp_count(l_tags,'\)')) then
98+
if ut_utils.valid_tag_expression(l_tags) = 0 then
10299
raise_application_error(ut_utils.gc_invalid_tag_expression, 'Invalid Tag expression');
103100
end if;
104-
*/
101+
105102
if a_random_test_order_seed is not null then
106103
l_random_test_order_seed := a_random_test_order_seed;
107104
elsif a_random_test_order then

‎source/core/ut_utils.pkb

Copy file name to clipboardExpand all lines: source/core/ut_utils.pkb
+62-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,68 @@ create or replace package body ut_utils is
988988

989989
return l_result;
990990
end;
991-
991+
992+
function valid_tag_expression(a_tags in varchar2) return number is
993+
t_left_side ut_varchar2_list := ut_varchar2_list('|','&',',');
994+
t_right_side ut_varchar2_list := ut_varchar2_list('!','-');
995+
l_left_side_expression varchar2(100) := '[|&,]';
996+
l_left_side_regex varchar(400) := '([^|&,]*)[|&,](.*)';
997+
l_left_side varchar2(4000);
998+
999+
l_rigth_side_expression varchar2(100) := '[!-]';
1000+
l_right_side_regex varchar(400) := '([!-])([^!-].*)';
1001+
l_right_side varchar2(4000);
1002+
1003+
l_tags varchar2(4000) := a_tags;
1004+
l_result number :=1;
1005+
begin
1006+
--Validate that we have closed up all brackets
1007+
if regexp_count(l_tags,'\(') <> regexp_count(l_tags,'\)') then
1008+
l_result := 0;
1009+
end if;
1010+
1011+
--Remove brackets as we dont evaluate expression only validate.
1012+
l_tags := replace(replace(l_tags,'('),')');
1013+
1014+
--Check if there are any left side operators for first in order from left to right
1015+
if regexp_count(l_tags,l_left_side_expression) > 0 then
1016+
--Extract left part of operator and remaining of string to right
1017+
l_left_side := regexp_replace(l_tags,l_left_side_regex,'\1');
1018+
l_right_side := regexp_replace(l_tags,l_left_side_regex,'\2');
1019+
1020+
--If left side is null that means that we used left side operator without
1021+
-- left and right e.g. &test
1022+
if l_left_side is null then
1023+
l_result := 0;
1024+
else
1025+
--Extract right side from left side expression if there is any !-
1026+
--Remove first negation tag to see if there is double negation
1027+
l_left_side := regexp_replace(l_left_side,l_right_side_regex,'\2');
1028+
end if;
1029+
1030+
1031+
--check that on right side there is no extra negation
1032+
if regexp_count(l_left_side,l_rigth_side_expression) > 0 then
1033+
l_result := 0;
1034+
end if;
1035+
1036+
--Now process right side of string
1037+
if l_right_side is not null then
1038+
l_result := least(l_result,valid_tag_expression(l_right_side));
1039+
else
1040+
l_result := 0;
1041+
end if;
1042+
else
1043+
--We just process single tag.
1044+
l_left_side := l_tags;
1045+
l_left_side := regexp_replace(l_left_side,l_right_side_regex,'\2');
1046+
if regexp_count(l_left_side,l_rigth_side_expression) > 0 then
1047+
l_result := 0;
1048+
end if;
1049+
end if;
1050+
1051+
return l_result;
1052+
end;
9921053

9931054
end ut_utils;
9941055
/

‎source/core/ut_utils.pks

Copy file name to clipboardExpand all lines: source/core/ut_utils.pks
+2
Original file line numberDiff line numberDiff line change
@@ -477,5 +477,7 @@ create or replace package ut_utils authid definer is
477477
*/
478478
function interval_to_text(a_interval yminterval_unconstrained) return varchar2;
479479

480+
function valid_tag_expression(a_tags in varchar2) return number;
481+
480482
end ut_utils;
481483
/

‎test/ut3_tester/core/test_ut_utils.pkb

Copy file name to clipboardExpand all lines: test/ut3_tester/core/test_ut_utils.pkb
+27
Original file line numberDiff line numberDiff line change
@@ -489,5 +489,32 @@ end;
489489
ut.expect(l_expected).to_equal(l_actual);
490490
end;
491491

492+
procedure valid_tag_expressions is
493+
begin
494+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('tag1'));
495+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('tag1|tag2'));
496+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('tag1&tag2'));
497+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('!tag1'));
498+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('tag1|!tag2'));
499+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('tag1&!tag2'));
500+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('!tag1|!tag2'));
501+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('!tag1&!tag2'));
502+
503+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('tag1,tag2'));
504+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('-tag1'));
505+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('tag1,-tag2'));
506+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('-tag1,-tag2'));
507+
508+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('(!tag1|!tag2)|tag3'));
509+
ut.expect(1).to_equal(ut3_develop.ut_utils.valid_tag_expression('(!tag1&!tag2)|(tag3&tag4)'));
510+
511+
ut.expect(0).to_equal(ut3_develop.ut_utils.valid_tag_expression('tag1|'));
512+
ut.expect(0).to_equal(ut3_develop.ut_utils.valid_tag_expression('&!tag2'));
513+
ut.expect(0).to_equal(ut3_develop.ut_utils.valid_tag_expression('!!tag1|!tag2'));
514+
ut.expect(0).to_equal(ut3_develop.ut_utils.valid_tag_expression('!tag1&!tag2|'));
515+
ut.expect(0).to_equal(ut3_develop.ut_utils.valid_tag_expression('((!tag1|!tag2)|tag3'));
516+
517+
end;
518+
492519
end test_ut_utils;
493520
/

‎test/ut3_tester/core/test_ut_utils.pks

Copy file name to clipboardExpand all lines: test/ut3_tester/core/test_ut_utils.pks
+2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ create or replace package test_ut_utils is
154154
--%test(returns text representation of interval year to month for custom interval)
155155
procedure int_conv_ym_date;
156156

157+
--%test(Test to validate different type of expressions passed as tags)
158+
procedure valid_tag_expressions;
157159

158160
--%endcontext
159161

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.