Skip to content

Commit 962f6fd

Browse files
committed
Resolves #1252
Replaced all regexp ranges with posix representations to avoid NLS_SORT impact on regex behavior.
1 parent 6a32cbd commit 962f6fd

File tree

10 files changed

+46
-19
lines changed

10 files changed

+46
-19
lines changed

source/core/annotations/ut_annotation_manager.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ create or replace package body ut_annotation_manager as
246246
l_sql_clob := regexp_replace(l_sql_clob, '^(.*?\s*create(\s+or\s+replace)?(\s+(editionable|noneditionable))?\s+?)((package|type).*)', '\5', 1, 1, 'ni');
247247
-- remove "OWNER." from create or replace statement.
248248
-- Owner is not supported along with AUTHID - see issue https://github.com/utPLSQL/utPLSQL/issues/1088
249-
l_sql_clob := regexp_replace(l_sql_clob, '^(package|type)\s+("?[a-zA-Z][a-zA-Z0-9#_$]*"?\.)(.*)', '\1 \3', 1, 1, 'ni');
249+
l_sql_clob := regexp_replace(l_sql_clob, '^(package|type)\s+("?[[:alpha:]][[:alnum:]$#_]*"?\.)(.*)', '\1 \3', 1, 1, 'ni');
250250
l_sql_lines := ut_utils.convert_collection( ut_utils.clob_to_table(l_sql_clob) );
251251
end if;
252252
open l_result for

source/core/annotations/ut_annotation_parser.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ create or replace package body ut_annotation_parser as
2525
gc_annot_comment_pattern constant varchar2(30) := '^( |'||chr(09)||')*-- *('||gc_annotation_qualifier||'.*?)$'; -- chr(09) is a tab character
2626
gc_comment_replacer_patter constant varchar2(50) := '{COMMENT#%N%}';
2727
gc_comment_replacer_regex_ptrn constant varchar2(25) := '{COMMENT#(\d+)}';
28-
gc_regexp_identifier constant varchar2(50) := '[a-zA-Z][a-zA-Z0-9#_$]*';
28+
gc_regexp_identifier constant varchar2(50) := '[[:alpha:]][[:alnum:]$#_]*';
2929
gc_annotation_block_pattern constant varchar2(200) := '(({COMMENT#.+}'||chr(10)||')+)( |'||chr(09)||')*(procedure|function)\s+(' ||
3030
gc_regexp_identifier || ')';
3131
gc_annotation_pattern constant varchar2(50) := gc_annotation_qualifier || gc_regexp_identifier || '[ '||chr(9)||']*(\(.*?\)\s*?$)?';

source/core/types/ut_executable_test.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ create or replace type body ut_executable_test as
159159
if self.error_stack is null then
160160
l_fail_message := 'Expected one of exceptions ('||l_expected_error_codes||') but nothing was raised.';
161161
else
162-
l_actual_error_no := regexp_substr(self.error_stack, '^[a-zA-Z]{3}(-[0-9]+)', subexpression=>1);
162+
l_actual_error_no := regexp_substr(self.error_stack, '^[[:alpha:]]{3}(-[0-9]+)', subexpression=>1);
163163
if not l_actual_error_no member of a_expected_error_codes or l_actual_error_no is null then
164164
l_fail_message := 'Actual: '||l_actual_error_no||' was expected to ';
165165
if cardinality(a_expected_error_codes) > 1 then

source/core/ut_expectation_processor.pkb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,17 @@ create or replace package body ut_expectation_processor as
159159
-- when 11g and 12c reports only package name
160160
function cut_header_and_expectations( a_stack varchar2 ) return varchar2 is
161161
begin
162-
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);
162+
return regexp_substr( a_stack, '(.*\.(UT_EQUAL|UT_BE_WITHIN[[:alnum:]$#_]*|UT_EXPECTATION[[:alnum:]$#_]*|UT|UTASSERT2?)(\.[[:alnum:]$#_]+)?\s+)+((.|\s)*)', 1, 1, 'm', 4);
163163
end;
164164
function cut_address_columns( a_stack varchar2 ) return varchar2 is
165165
begin
166-
return regexp_replace( a_stack, '^(0x)?[0-9a-f]+\s+', '', 1, 0, 'mi' );
166+
return regexp_replace( a_stack, '^(0x)?[[:digit:]abcdef]+\s+', '', 1, 0, 'mi' );
167167
end;
168168
function cut_framework_stack( a_stack varchar2 ) return varchar2 is
169169
begin
170170
return regexp_replace(
171171
a_stack,
172-
'[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.*',
172+
'[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.*',
173173
'',
174174
1, 1, 'mni'
175175
);
@@ -178,7 +178,7 @@ create or replace package body ut_expectation_processor as
178178
begin
179179
return regexp_replace(
180180
a_stack,
181-
'([0-9]+)\s+(.* )?((anonymous block)|(([0-9_$#a-z]+\.[0-9_$#a-z]+(\.([0-9_$#a-z])+)?)))',
181+
'([0-9]+)\s+(.* )?((anonymous block)|(([[:alnum:]$#_]+\.[[:alnum:]$#_]+(\.([[:alnum:]$#_])+)?)))',
182182
'at "\3", line \1', 1, 0, 'i'
183183
);
184184
end;
@@ -190,8 +190,8 @@ create or replace package body ut_expectation_processor as
190190
l_caller_stack_line := regexp_substr(l_call_stack,'^(.*)');
191191
if l_caller_stack_line like '%.%' then
192192
l_line_no := to_number( regexp_substr( l_caller_stack_line, ', line (\d+)', subexpression => 1 ) );
193-
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 );
194-
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 );
193+
l_owner := regexp_substr( l_caller_stack_line, 'at "([[:alnum:]$#_]+)\.(([[:alnum:]$#_]+)(\.([[:alnum:]$#_]+))?)", line (\d+)', subexpression => 1 );
194+
l_object_name := regexp_substr( l_caller_stack_line, 'at "([[:alnum:]$#_]+)\.(([[:alnum:]$#_]+)(\.([[:alnum:]$#_]+))?)", line (\d+)', subexpression => 3 );
195195
l_result :=
196196
l_caller_stack_line || ' ' || rtrim(ut_metadata.get_source_definition_line(l_owner, l_object_name, l_line_no),chr(10))
197197
|| replace( l_call_stack, l_caller_stack_line );

source/core/ut_metadata.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ create or replace package body ut_metadata as
304304
begin
305305
l_result := regexp_substr(
306306
a_full_object_name,
307-
'^([A-Za-z0-9$#_]+|".*?")\.([A-Za-z0-9$#_]+|".*?")', subexpression => 2
307+
'^([[:alnum:]$#_]+|".*?")\.([[:alnum:]$#_]+|".*?")', subexpression => 2
308308
);
309309
if not l_result like '"%"' then
310310
l_result := upper(l_result);

source/core/ut_suite_cache_manager.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ create or replace package body ut_suite_cache_manager is
8888
end;
8989

9090
function group_paths_by_schema(a_paths ut_varchar2_list) return ut_path_items is
91-
c_package_path_regex constant varchar2(100) := '^([A-Za-z0-9$#_]+)(\.([A-Za-z0-9$#_\*]+))?(\.([A-Za-z0-9$#_\*]+))?$';
91+
c_package_path_regex constant varchar2(100) := '^([[:alnum:]$#_]+)(\.([[:alnum:]$#_\*]+))?(\.([[:alnum:]$#_\*]+))?$';
9292
l_results ut_path_items := ut_path_items();
9393
l_path_item ut_path_item;
9494
i pls_integer;
@@ -157,7 +157,7 @@ create or replace package body ut_suite_cache_manager is
157157
from schema_paths sp left outer join ut_suite_cache c on
158158
( c.object_owner = upper(sp.schema_name)
159159
--and c.path like replace(sp.suite_path,'*','%'))
160-
and regexp_like(c.path,'^'||replace(sp.suite_path,'*','[A-Za-z0-9$#_]*')))
160+
and regexp_like(c.path,'^'||replace(sp.suite_path,'*','[[:alnum:]$#_]*')))
161161
where sp.suite_path is not null and instr(sp.suite_path,'*') > 0
162162
),
163163
straigth_suite_paths as (

source/core/ut_suite_manager.pkb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ create or replace package body ut_suite_manager is
3232
for i in 1 .. a_paths.count loop
3333
l_path := a_paths(i);
3434
if l_path is null or not (
35-
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
35+
regexp_like(l_path, '^[[:alnum:]$#_\*]+(\.[[:alnum:]$#_\*]+){0,2}$') or regexp_like(l_path, '^([[:alnum:]$#_]+)?:[[:alnum:]$#_\*]+(\.[[:alnum:]$#_\*]+)*$')) then
3636
raise_application_error(ut_utils.gc_invalid_path_format, 'Invalid path format: ' || nvl(l_path, 'NULL'));
3737
end if;
3838
end loop;
@@ -61,9 +61,9 @@ create or replace package body ut_suite_manager is
6161

6262
for i in 1 .. a_paths.count loop
6363
--if path is suite-path
64-
if regexp_like(a_paths(i), '^([A-Za-z0-9$#_]+)?:') then
64+
if regexp_like(a_paths(i), '^([[:alnum:]$#_]+)?:') then
6565
--get schema name / path
66-
l_schema := regexp_substr(a_paths(i), '^([A-Za-z0-9$#_]+)?:',subexpression => 1);
66+
l_schema := regexp_substr(a_paths(i), '^([[:alnum:]$#_]+)?:',subexpression => 1);
6767
-- transform ":path1[.path2]" to "schema:path1[.path2]"
6868
if l_schema is not null then
6969
l_schema := sys.dbms_assert.schema_name(upper(l_schema));
@@ -78,7 +78,7 @@ create or replace package body ut_suite_manager is
7878
-- Object name or procedure is allowed to have filter char
7979
-- However this is not allowed on schema
8080
begin
81-
l_object := regexp_substr(a_paths(i), '^[A-Za-z0-9$#_\*]+');
81+
l_object := regexp_substr(a_paths(i), '^[[:alnum:]$#_\*]+');
8282
l_schema := sys.dbms_assert.schema_name(upper(l_object));
8383
exception
8484
when sys.dbms_assert.invalid_schema_name then

source/core/ut_utils.pkb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ create or replace package body ut_utils is
1919
/**
2020
* Constants regex used to validate XML name
2121
*/
22-
gc_invalid_first_xml_char constant varchar2(50) := '[^_a-zA-Z]';
23-
gc_invalid_xml_char constant varchar2(50) := '[^_a-zA-Z0-9\.-]';
24-
gc_full_valid_xml_name constant varchar2(50) := '^([_a-zA-Z])([_a-zA-Z0-9\.-])*$';
22+
gc_invalid_first_xml_char constant varchar2(50) := '[^_[:alpha:]]';
23+
gc_invalid_xml_char constant varchar2(50) := '[^_[:alnum:]\.-]';
24+
gc_full_valid_xml_name constant varchar2(50) := '^([[:alpha:]])([_[:alnum:]\.-])*$';
2525
gc_owner_hash constant integer(11) := dbms_utility.get_hash_value( ut_owner(), 0, power(2,31)-1);
2626

2727

test/ut3_tester/core/test_suite_manager.pkb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,5 +2217,22 @@ end;]';
22172217
end loop;
22182218
end;
22192219

2220+
--%test(Path validation does not fail on Estonian NLS_SORT - fix #1252)
2221+
procedure path_validate_nls_sort is
2222+
l_schema_names ut3_develop.ut_varchar2_rows;
2223+
begin
2224+
--Arrange
2225+
execute immediate q'[alter session set nls_sort='estonian']';
2226+
--Act
2227+
l_schema_names := ut3_develop.ut_suite_manager.get_schema_names(ut3_develop.ut_varchar2_list('ut3'));
2228+
--Asseert
2229+
ut.expect(sqlcode).to_equal(0);
2230+
end;
2231+
2232+
2233+
procedure reset_nls_sort is
2234+
begin
2235+
execute immediate q'[alter session set nls_sort='binary']';
2236+
end;
22202237
end test_suite_manager;
22212238
/

test/ut3_tester/core/test_suite_manager.pks

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,15 @@ create or replace package test_suite_manager is
237237

238238
--%endcontext
239239

240+
--%context(paths validation)
241+
242+
--%test(Path validation does not fail on Estonian NLS_SORT - fix #1252)
243+
--%aftertest(reset_nls_sort)
244+
procedure path_validate_nls_sort;
245+
246+
procedure reset_nls_sort;
247+
248+
--%endcontext
249+
240250
end test_suite_manager;
241251
/

0 commit comments

Comments
 (0)