Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix regex to be NLS_SORT independent #1253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/core/annotations/ut_annotation_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ create or replace package body ut_annotation_manager as
l_sql_clob := regexp_replace(l_sql_clob, '^(.*?\s*create(\s+or\s+replace)?(\s+(editionable|noneditionable))?\s+?)((package|type).*)', '\5', 1, 1, 'ni');
-- remove "OWNER." from create or replace statement.
-- Owner is not supported along with AUTHID - see issue https://github.com/utPLSQL/utPLSQL/issues/1088
l_sql_clob := regexp_replace(l_sql_clob, '^(package|type)\s+("?[a-zA-Z][a-zA-Z0-9#_$]*"?\.)(.*)', '\1 \3', 1, 1, 'ni');
l_sql_clob := regexp_replace(l_sql_clob, '^(package|type)\s+("?[[:alpha:]][[:alnum:]$#_]*"?\.)(.*)', '\1 \3', 1, 1, 'ni');
l_sql_lines := ut_utils.convert_collection( ut_utils.clob_to_table(l_sql_clob) );
end if;
open l_result for
Expand Down
2 changes: 1 addition & 1 deletion source/core/annotations/ut_annotation_parser.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ create or replace package body ut_annotation_parser as
gc_annot_comment_pattern constant varchar2(30) := '^( |'||chr(09)||')*-- *('||gc_annotation_qualifier||'.*?)$'; -- chr(09) is a tab character
gc_comment_replacer_patter constant varchar2(50) := '{COMMENT#%N%}';
gc_comment_replacer_regex_ptrn constant varchar2(25) := '{COMMENT#(\d+)}';
gc_regexp_identifier constant varchar2(50) := '[a-zA-Z][a-zA-Z0-9#_$]*';
gc_regexp_identifier constant varchar2(50) := '[[:alpha:]][[:alnum:]$#_]*';
gc_annotation_block_pattern constant varchar2(200) := '(({COMMENT#.+}'||chr(10)||')+)( |'||chr(09)||')*(procedure|function)\s+(' ||
gc_regexp_identifier || ')';
gc_annotation_pattern constant varchar2(50) := gc_annotation_qualifier || gc_regexp_identifier || '[ '||chr(9)||']*(\(.*?\)\s*?$)?';
Expand Down
2 changes: 1 addition & 1 deletion source/core/types/ut_executable_test.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ create or replace type body ut_executable_test as
if self.error_stack is null then
l_fail_message := 'Expected one of exceptions ('||l_expected_error_codes||') but nothing was raised.';
else
l_actual_error_no := regexp_substr(self.error_stack, '^[a-zA-Z]{3}(-[0-9]+)', subexpression=>1);
l_actual_error_no := regexp_substr(self.error_stack, '^[[:alpha:]]{3}(-[0-9]+)', subexpression=>1);
if not l_actual_error_no member of a_expected_error_codes or l_actual_error_no is null then
l_fail_message := 'Actual: '||l_actual_error_no||' was expected to ';
if cardinality(a_expected_error_codes) > 1 then
Expand Down
12 changes: 6 additions & 6 deletions source/core/ut_expectation_processor.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,17 @@ create or replace package body ut_expectation_processor as
-- when 11g and 12c reports only package name
function cut_header_and_expectations( a_stack varchar2 ) return varchar2 is
begin
return regexp_substr( a_stack, '(.*\.(UT_EQUAL|UT_BE_WITHIN[A-Z0-9#_$]*|UT_EXPECTATION[A-Z0-9#_$]*|UT|UTASSERT2?)(\.[A-Z0-9#_$]+)?\s+)+((.|\s)*)', 1, 1, 'm', 4);
return regexp_substr( a_stack, '(.*\.(UT_EQUAL|UT_BE_WITHIN[[:alnum:]$#_]*|UT_EXPECTATION[[:alnum:]$#_]*|UT|UTASSERT2?)(\.[[:alnum:]$#_]+)?\s+)+((.|\s)*)', 1, 1, 'm', 4);
end;
function cut_address_columns( a_stack varchar2 ) return varchar2 is
begin
return regexp_replace( a_stack, '^(0x)?[0-9a-f]+\s+', '', 1, 0, 'mi' );
return regexp_replace( a_stack, '^(0x)?[[:digit:]abcdef]+\s+', '', 1, 0, 'mi' );
end;
function cut_framework_stack( a_stack varchar2 ) return varchar2 is
begin
return regexp_replace(
a_stack,
'[0-9]+\s+anonymous\s+block\s+[0-9]+\s+package\s+body\s+sys\.dbms_sql(\.execute)?\s+[0-9]+\s+[0-9_$#a-z ]+\.ut_executable.*',
'[0-9]+\s+anonymous\s+block\s+[0-9]+\s+package\s+body\s+sys\.dbms_sql(\.execute)?\s+[0-9]+\s+[[:alnum:]_$# ]+\.ut_executable.*',
'',
1, 1, 'mni'
);
Expand All @@ -178,7 +178,7 @@ create or replace package body ut_expectation_processor as
begin
return regexp_replace(
a_stack,
'([0-9]+)\s+(.* )?((anonymous block)|(([0-9_$#a-z]+\.[0-9_$#a-z]+(\.([0-9_$#a-z])+)?)))',
'([0-9]+)\s+(.* )?((anonymous block)|(([[:alnum:]$#_]+\.[[:alnum:]$#_]+(\.([[:alnum:]$#_])+)?)))',
'at "\3", line \1', 1, 0, 'i'
);
end;
Expand All @@ -190,8 +190,8 @@ create or replace package body ut_expectation_processor as
l_caller_stack_line := regexp_substr(l_call_stack,'^(.*)');
if l_caller_stack_line like '%.%' then
l_line_no := to_number( regexp_substr( l_caller_stack_line, ', line (\d+)', subexpression => 1 ) );
l_owner := regexp_substr( l_caller_stack_line, 'at "([A-Za-z0-9$#_]+)\.(([A-Za-z0-9$#_]+)(\.([A-Za-z0-9$#_]+))?)", line (\d+)', subexpression => 1 );
l_object_name := regexp_substr( l_caller_stack_line, 'at "([A-Za-z0-9$#_]+)\.(([A-Za-z0-9$#_]+)(\.([A-Za-z0-9$#_]+))?)", line (\d+)', subexpression => 3 );
l_owner := regexp_substr( l_caller_stack_line, 'at "([[:alnum:]$#_]+)\.(([[:alnum:]$#_]+)(\.([[:alnum:]$#_]+))?)", line (\d+)', subexpression => 1 );
l_object_name := regexp_substr( l_caller_stack_line, 'at "([[:alnum:]$#_]+)\.(([[:alnum:]$#_]+)(\.([[:alnum:]$#_]+))?)", line (\d+)', subexpression => 3 );
l_result :=
l_caller_stack_line || ' ' || rtrim(ut_metadata.get_source_definition_line(l_owner, l_object_name, l_line_no),chr(10))
|| replace( l_call_stack, l_caller_stack_line );
Expand Down
2 changes: 1 addition & 1 deletion source/core/ut_metadata.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ create or replace package body ut_metadata as
begin
l_result := regexp_substr(
a_full_object_name,
'^([A-Za-z0-9$#_]+|".*?")\.([A-Za-z0-9$#_]+|".*?")', subexpression => 2
'^([[:alnum:]$#_]+|".*?")\.([[:alnum:]$#_]+|".*?")', subexpression => 2
);
if not l_result like '"%"' then
l_result := upper(l_result);
Expand Down
4 changes: 2 additions & 2 deletions source/core/ut_suite_cache_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ create or replace package body ut_suite_cache_manager is
end;

function group_paths_by_schema(a_paths ut_varchar2_list) return ut_path_items is
c_package_path_regex constant varchar2(100) := '^([A-Za-z0-9$#_]+)(\.([A-Za-z0-9$#_\*]+))?(\.([A-Za-z0-9$#_\*]+))?$';
c_package_path_regex constant varchar2(100) := '^([[:alnum:]$#_]+)(\.([[:alnum:]$#_\*]+))?(\.([[:alnum:]$#_\*]+))?$';
l_results ut_path_items := ut_path_items();
l_path_item ut_path_item;
i pls_integer;
Expand Down Expand Up @@ -157,7 +157,7 @@ create or replace package body ut_suite_cache_manager is
from schema_paths sp left outer join ut_suite_cache c on
( c.object_owner = upper(sp.schema_name)
--and c.path like replace(sp.suite_path,'*','%'))
and regexp_like(c.path,'^'||replace(sp.suite_path,'*','[A-Za-z0-9$#_]*')))
and regexp_like(c.path,'^'||replace(sp.suite_path,'*','[[:alnum:]$#_]*')))
where sp.suite_path is not null and instr(sp.suite_path,'*') > 0
),
straigth_suite_paths as (
Expand Down
8 changes: 4 additions & 4 deletions source/core/ut_suite_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ create or replace package body ut_suite_manager is
for i in 1 .. a_paths.count loop
l_path := a_paths(i);
if l_path is null or not (
regexp_like(l_path, '^[A-Za-z0-9$#_\*]+(\.[A-Za-z0-9$#_\*]+){0,2}$') or regexp_like(l_path, '^([A-Za-z0-9$#_]+)?:[A-Za-z0-9$#_\*]+(\.[A-Za-z0-9$#_\*]+)*$')) then
regexp_like(l_path, '^[[:alnum:]$#_\*]+(\.[[:alnum:]$#_\*]+){0,2}$') or regexp_like(l_path, '^([[:alnum:]$#_]+)?:[[:alnum:]$#_\*]+(\.[[:alnum:]$#_\*]+)*$')) then
raise_application_error(ut_utils.gc_invalid_path_format, 'Invalid path format: ' || nvl(l_path, 'NULL'));
end if;
end loop;
Expand Down Expand Up @@ -61,9 +61,9 @@ create or replace package body ut_suite_manager is

for i in 1 .. a_paths.count loop
--if path is suite-path
if regexp_like(a_paths(i), '^([A-Za-z0-9$#_]+)?:') then
if regexp_like(a_paths(i), '^([[:alnum:]$#_]+)?:') then
--get schema name / path
l_schema := regexp_substr(a_paths(i), '^([A-Za-z0-9$#_]+)?:',subexpression => 1);
l_schema := regexp_substr(a_paths(i), '^([[:alnum:]$#_]+)?:',subexpression => 1);
-- transform ":path1[.path2]" to "schema:path1[.path2]"
if l_schema is not null then
l_schema := sys.dbms_assert.schema_name(upper(l_schema));
Expand All @@ -78,7 +78,7 @@ create or replace package body ut_suite_manager is
-- Object name or procedure is allowed to have filter char
-- However this is not allowed on schema
begin
l_object := regexp_substr(a_paths(i), '^[A-Za-z0-9$#_\*]+');
l_object := regexp_substr(a_paths(i), '^[[:alnum:]$#_\*]+');
l_schema := sys.dbms_assert.schema_name(upper(l_object));
exception
when sys.dbms_assert.invalid_schema_name then
Expand Down
6 changes: 3 additions & 3 deletions source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ create or replace package body ut_utils is
/**
* Constants regex used to validate XML name
*/
gc_invalid_first_xml_char constant varchar2(50) := '[^_a-zA-Z]';
gc_invalid_xml_char constant varchar2(50) := '[^_a-zA-Z0-9\.-]';
gc_full_valid_xml_name constant varchar2(50) := '^([_a-zA-Z])([_a-zA-Z0-9\.-])*$';
gc_invalid_first_xml_char constant varchar2(50) := '[^_[:alpha:]]';
gc_invalid_xml_char constant varchar2(50) := '[^_[:alnum:]\.-]';
gc_full_valid_xml_name constant varchar2(50) := '^([[:alpha:]])([_[:alnum:]\.-])*$';
gc_owner_hash constant integer(11) := dbms_utility.get_hash_value( ut_owner(), 0, power(2,31)-1);


Expand Down
17 changes: 17 additions & 0 deletions test/ut3_tester/core/test_suite_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -2217,5 +2217,22 @@ end;]';
end loop;
end;

--%test(Path validation does not fail on Estonian NLS_SORT - fix #1252)
procedure path_validate_nls_sort is
l_schema_names ut3_develop.ut_varchar2_rows;
begin
--Arrange
execute immediate q'[alter session set nls_sort='estonian']';
--Act
l_schema_names := ut3_develop.ut_suite_manager.get_schema_names(ut3_develop.ut_varchar2_list('ut3'));
--Asseert
ut.expect(sqlcode).to_equal(0);
end;


procedure reset_nls_sort is
begin
execute immediate q'[alter session set nls_sort='binary']';
end;
end test_suite_manager;
/
10 changes: 10 additions & 0 deletions test/ut3_tester/core/test_suite_manager.pks
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,15 @@ create or replace package test_suite_manager is

--%endcontext

--%context(paths validation)

--%test(Path validation does not fail on Estonian NLS_SORT - fix #1252)
--%aftertest(reset_nls_sort)
procedure path_validate_nls_sort;

procedure reset_nls_sort;

--%endcontext

end test_suite_manager;
/