Skip to content

Commit

Permalink
issue 5054
Browse files Browse the repository at this point in the history
  • Loading branch information
droelandt committed Mar 29, 2024
1 parent af7c18f commit fded33e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions atest/robot/standard_libraries/builtin/should_contain.robot
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Should Contain and do not collapse spaces
Should Contain and collapse spaces
Check Test Case ${TESTNAME}

Should Contain for bytes
Check Test Case ${TESTNAME}

Should Not Contain
Check test case ${TESTNAME}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ Should Contain and collapse spaces
${LIST4} \tb\n collapse_spaces=TRUE
${LIST4} \tc\n collapse_spaces=TRUE

Should Contain for bytes
[Documentation] FAIL ValueError: byte must be in range(0, 256)
[Template] Should Contain
${BINARY} \xA0
${BINARY} ${1000}

Should Not Contain
[Documentation] FAIL 'Hello yet again' contains 'yet'
[Template] Should Not Contain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def get_variables():
DICT_3={'a': 1, 'b': 2, 'c': 3},
DICT_4={'\ta': 1, 'a b': 2, ' c': 3, 'dd\n\t': 4, '\nak \t': 5},
DICT_5={' a': 0, '\ta': 1, 'a\t': 2, '\nb': 3, 'd\t': 4, '\td\n': 5, 'e e': 6},
PREPR_DICT1="{'a': 1}"
PREPR_DICT1="{'a': 1}",
BINARY=b'\x00\x01\x02\xA0\xB0'
)
variables['ASCII_DICT'] = ascii(variables['DICT'])
return variables
5 changes: 5 additions & 0 deletions src/robot/libraries/BuiltIn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,11 @@ def should_contain(self, container, item, msg=None, values=True,
in Robot Framework 4.1.
"""
orig_container = container
if isinstance(container, bytes) and isinstance(item, str):
try:
item = item.encode('latin-1')
except UnicodeEncodeError:
raise ValueError("{item} can not be encoded into bytes.")
if ignore_case and is_string(item):
item = item.casefold()
if is_string(container):
Expand Down

0 comments on commit fded33e

Please sign in to comment.