Skip to content
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
7 changes: 3 additions & 4 deletions cbxp/control_blocks/control_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ void ControlBlock::addCurrentFilter(const std::string& filter) {
// If there's a delimeter then separate include into the key and its value
filter_value = filter.substr(operation_pos + operation.length());
filter_key = filter.substr(0, operation_pos);
if (filter_value == "") {
Logger::getInstance().debug("Filter values cannot be null");
throw FilterError();
}
cbxp_filter_t filter_data = {operation, filter_value};
Logger::getInstance().debug("Adding '" + filter_key + operation +
filter_value +
Expand All @@ -182,6 +178,9 @@ void ControlBlock::addCurrentFilter(const std::string& filter) {
return;
}
}
Logger::getInstance().debug(
"Filters must be key-value pairs (e.g., 'key=value')");
throw FilterError();
}

bool ControlBlock::compare(const nlohmann::json& json_value,
Expand Down
3 changes: 2 additions & 1 deletion cbxp/control_blocks/control_block_field_formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class ControlBlockFieldFormatter {
std::memcpy(ascii_field_tmp.data(), p_field, length);
__e2a_l(ascii_field_tmp.data(), length);
std::string ascii_field(ascii_field_tmp.begin(), ascii_field_tmp.end());
size_t last_non_space = ascii_field.find_last_not_of(" \t\n\r\f\v");
size_t last_non_space =
ascii_field.find_last_not_of({'\0', ' ', '\t', '\n', '\r', '\f', '\v'});
ascii_field.resize(last_non_space + 1);
return ascii_field;
}
Expand Down
49 changes: 38 additions & 11 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_cbxp_can_extract_assb(self):
self.assertIs(type(cbdata), list)
for entry in cbdata:
self.assertIs(type(entry), dict)

def test_cbxp_can_extract_oucb(self):
cbdata = cbxp("oucb")
self.assertIs(type(cbdata), list)
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_cbxp_can_extract_the_ascb_and_include_the_assb(self):
for entry in cbdata:
self.assertIs(type(entry), dict)
self.assertIs(type(entry["ascbassb"]), dict)

def test_cbxp_can_extract_the_ascb_and_include_the_oucb(self):
cbdata = cbxp("ascb", includes=["oucb"])
self.assertIs(type(cbdata), list)
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_cbxp_include_can_extract_psa_and_include_ecvt_asvt_and_cvt_asvt_ascb_as
for entry in cbdata["flccvt"]["cvtasvt"]["asvtenty"]:
self.assertIs(type(entry), dict)
self.assertIs(type(entry["ascbassb"]), dict)

def test_cbxp_include_can_extract_psa_and_include_ecvt_asvt_and_cvt_asvt_ascb_oucb(
self,
):
Expand Down Expand Up @@ -197,7 +197,6 @@ def test_cbxp_can_extract_cvt_and_include_wildcard_and_asvt_recursive_wildcard(
self.assertIs(type(entry["ascbassb"]), dict)
self.assertIs(type(entry["ascboucb"]), dict)


# ============================================================================
# Filters
# ============================================================================
Expand All @@ -207,7 +206,7 @@ def test_cbxp_can_use_filter(self):
filters=[CBXPFilter("psapsa", CBXPFilterOperation.EQUAL, "PSA")],
)
self.assertIs(type(cbdata), dict)

def test_cbxp_can_use_filter_with_wildcard_include(self):
cbdata = cbxp(
"psa",
Expand Down Expand Up @@ -434,8 +433,7 @@ def test_cbxp_can_use_filter_oucbtrxn_from_oucb(self):
for entry in cbdata:
self.assertIs(type(entry), dict)
self.assertEqual(entry["oucbtrxn"], "OMVS")



def test_cbxp_can_use_filter_on_ascb_oucb_oucbtrxn_with_explicit_include_oucb(self):
cbdata = cbxp(
"ascb",
Expand All @@ -453,7 +451,26 @@ def test_cbxp_can_use_filter_on_ascb_oucb_oucbtrxn_with_explicit_include_oucb(se
self.assertIs(type(entry), dict)
self.assertIs(type(entry["ascboucb"]), dict)
self.assertEqual(entry["ascboucb"]["oucbtrxn"], "OMVS")


def test_cbxp_can_use_null_filter_string(
self,
):
cbdata = cbxp(
"assb",
filters=[
CBXPFilter(
"assbjbns",
CBXPFilterOperation.EQUAL,
"*MASTER*",
),
CBXPFilter(
"assbjbni",
CBXPFilterOperation.EQUAL,
"",
),
],
)
self.assertIs(type(cbdata), list)

# ============================================================================
# Debug Mode
Expand Down Expand Up @@ -568,13 +585,13 @@ def test_cbxp_raises_cbxp_error_if_filter_uses_unknown_key(
)
self.assertEqual("A bad filter was provided", str(e.exception))

def test_cbxp_raises_cbxp_error_if_filter_passes_null_value(
def test_cbxp_raises_cbxp_error_if_filter_passes_null_value_for_non_string(
self,
):
with self.assertRaises(CBXPError) as e:
cbxp(
"psa",
filters=["psapsa", CBXPFilterOperation.EQUAL, ""],
"assb",
filters=["assbasid", CBXPFilterOperation.EQUAL, ""],
)
self.assertEqual("A bad filter was provided", str(e.exception))

Expand All @@ -588,6 +605,16 @@ def test_cbxp_raises_cbxp_error_if_filter_uses_string_for_numeric_field(
)
self.assertEqual("A bad filter was provided", str(e.exception))

def test_cbxp_raises_cbxp_error_if_no_operation_provided(
self,
):
with self.assertRaises(CBXPError) as e:
cbxp(
"psa",
filters=["junk", None, ""],
)
self.assertEqual("A bad filter was provided", str(e.exception))

def test_cbxp_raises_cbxp_error_if_filter_has_comma(
self,
):
Expand Down
7 changes: 6 additions & 1 deletion tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ run_with_expected_exit_code 0 ./dist/cbxp -f 'oucbtrxn=OMVS' oucb
run_with_expected_exit_code 0 ./dist/cbxp -i oucb -f 'oucb.oucbtrxn=OMVS' ascb
run_with_expected_null_response ./dist/cbxp -f psapsa=PSB psa
run_with_expected_null_response ./dist/cbxp -f "ascb.assb.assbjbns=*MASTER*" -f "ascb.ascbasid=2" -i ascb.assb asvt
run_with_expected_exit_code 0 ./dist/cbxp -f assbjbns="*MASTER*" -f assbjbni= assb
run_with_expected_exit_code 0 ./dist/cbxp -f assbjbns="*MASTER*" -f assbjbni="" assb
run_with_expected_exit_code 0 ./dist/cbxp -f assbjbns="*MASTER*" -f assbjbni='' assb


# Debug Mode
run_with_expected_exit_code 0 ./dist/cbxp -d psa
Expand Down Expand Up @@ -115,9 +119,10 @@ run_with_expected_exit_code 255 ./dist/cbxp -i cvt cvt
run_with_expected_exit_code 255 ./dist/cbxp -f "cvt.asvt.ascb.assb.assbjbns=*master*" psa
run_with_expected_exit_code 255 ./dist/cbxp -f "cvt.asvt.ascb.assb.assbjbns<*master*" -i "**" psa
run_with_expected_exit_code 255 ./dist/cbxp -f psapsb=PSA psa
run_with_expected_exit_code 255 ./dist/cbxp -f psapsa= psa
run_with_expected_exit_code 255 ./dist/cbxp -f assbasid= assb
run_with_expected_exit_code 255 ./dist/cbxp -f 'ascbasid<=junk' ascb
run_with_expected_exit_code 255 ./dist/cbxp -f "psapsa=psa,cvt.asvt.ascb.ascbasid<2" cvt
run_with_expected_exit_code 255 ./dist/cbxp -f junk psa

echo " -------------------------------- "
echo " -------------------------------- "
Expand Down