Merge remote-tracking branch 'origin/topic/christian/gh-1982'

* origin/topic/christian/gh-1982:
  The is_num(), is_alpha(), and is_alnum() BiFs now return F on empty string
  Expand testcases around is_num(), is_alpha(), is_alnum(), is_ascii() BiFs
  Clarify is_ascii() BiF docstring re behavior on empty strings
  Fix minor indentation bugs in strings.bif
This commit is contained in:
Johanna Amann 2022-03-02 08:23:50 +00:00
commit f264a9eccf
8 changed files with 35 additions and 6 deletions

View file

@ -1,3 +1,9 @@
5.0.0-dev.156 | 2022-03-02 08:23:50 +0000
* The is_num(), is_alpha(), and is_alnum() BiFs now return F on empty string.
The testcases for these functions, and for is_ascii() were expanded. The documentation of is_ascii()
concerning behavior of an empty string was clarified (Christian Kreibich, Corelight)
5.0.0-dev.151 | 2022-03-02 08:09:28 +0000
* SSL: rudimentary decryption for TLS 1.2 (Florian Wilkens, Johanna Amann)

2
NEWS
View file

@ -15,6 +15,8 @@ New Functionality
Changed Functionality
---------------------
- The is_num(), is_alpha(), and is_alnum() BiFs now return F for the empty string.
Deprecated Functionality
------------------------

View file

@ -1 +1 @@
5.0.0-dev.151
5.0.0-dev.156

View file

@ -614,6 +614,7 @@ function to_string_literal%(str: string%): string
%}
## Determines whether a given string contains only ASCII characters.
## The empty string is ASCII.
##
## str: The string to examine.
##
@ -1253,13 +1254,17 @@ function ends_with%(str: string, sub: string%) : bool
return zeek::val_mgr->Bool(s.rfind(sub_s) == (s.size() - sub_s.size()));
%}
## Returns whether an entire string consists only of digits.
## Returns whether a string consists entirely of digits.
## The empty string is not numeric.
##
function is_num%(str: string%) : bool
%{
// Python's version of this method (which this is based on) just checks to see if every
// character in the string is a numeric value. If something more than this is desired, we
// could use something like std::from_chars or std::strto{ul,f} to check it.
if ( str->Len() == 0 )
return zeek::val_mgr->False();
const char* s = str->CheckString();
for ( int i = 0; i < str->Len(); i++ )
if ( ! std::isdigit(s[i]) )
@ -1268,10 +1273,14 @@ function is_num%(str: string%) : bool
return zeek::val_mgr->True();
%}
## Returns whether an entire string is alphabetic characters.
## Returns whether a string consists entirely of alphabetic characters.
## The empty string is not alphabetic.
##
function is_alpha%(str: string%) : bool
%{
if ( str->Len() == 0 )
return zeek::val_mgr->False();
const char* s = str->CheckString();
for ( int i = 0; i < str->Len(); i++ )
if ( ! std::isalpha(s[i]) )
@ -1280,10 +1289,14 @@ function is_alpha%(str: string%) : bool
return zeek::val_mgr->True();
%}
## Returns whether an entire string is alphanumeric characters
## Returns whether a string consists entirely of alphanumeric characters.
## The empty string is not alphanumeric.
##
function is_alnum%(str: string%) : bool
%{
if ( str->Len() == 0 )
return zeek::val_mgr->False();
const char* s = str->CheckString();
for ( int i = 0; i < str->Len(); i++ )
if ( ! std::isalnum(s[i]) )

View file

@ -1,3 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
F
T
T

View file

@ -17,14 +17,17 @@ Content checking
----------------
is_num abc : 0
is_num 123 : 1
is_num '' : 0
is_alpha ab : 1
is_alpha 1a : 0
is_alpha a1 : 0
is_alpha '' : 0
is_alnum ab : 1
is_alnum 1a : 1
is_alnum a1 : 1
is_alnum 12 : 1
is_alnum ##12: 0
is_alnum '' : 0
String counting (input str 'aabbaa')
------------------------------------

View file

@ -9,4 +9,5 @@ event zeek_init()
print is_ascii(a);
print is_ascii(b);
print is_ascii("");
}

View file

@ -23,14 +23,17 @@ event zeek_init()
print "----------------";
print fmt("is_num abc : %d", is_num("abc"));
print fmt("is_num 123 : %d", is_num("123"));
print fmt("is_num '' : %d", is_num(""));
print fmt("is_alpha ab : %d", is_alpha("ab"));
print fmt("is_alpha 1a : %d", is_alpha("1a"));
print fmt("is_alpha a1 : %d", is_alpha("a1"));
print fmt("is_alpha '' : %d", is_alpha(""));
print fmt("is_alnum ab : %d", is_alnum("ab"));
print fmt("is_alnum 1a : %d", is_alnum("1a"));
print fmt("is_alnum a1 : %d", is_alnum("a1"));
print fmt("is_alnum 12 : %d", is_alnum("12"));
print fmt("is_alnum ##12: %d", is_alnum("##12"));
print fmt("is_alnum '' : %d", is_alnum(""));
print "";
print "String counting (input str 'aabbaa')";