Skip to content
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

Fixes #1312 Fixed IndexError in tomof() of some CIM objects on empty array value #1313

Merged
merged 1 commit into from
Jul 20, 2018
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 PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.2
Name: pywbem
Version: 0.12.1.dev54
Version: 0.12.1.dev59
Summary: pywbem - A WBEM client
Home-page: http://pywbem.github.io/pywbem/
Author: Tim Potter
Expand Down
7 changes: 7 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ Released: not yet
variables. They are no longer imported into the `pywbem` namespace.
See issue #1302.

* Fixed issue where the `tomof()` methods of `CIMProperty`, `CIMQualifier`,
and `CIMQualifierDeclaration` raised `IndexError` when the value was
an empty array. This issue perculated up to higher level CIM objects
that are using these objects, i.e. `CIMInstance` or `CIMClass`.
Added according testcases.
See issue #1312.

**Enhancements:**

* Extend pywbem MOF compiler to search for dependent classes including:
Expand Down
7 changes: 5 additions & 2 deletions pywbem/cim_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -4782,7 +4782,8 @@ def tomof(
val_str, line_pos = _value_tomof(
self.value, self.type, indent + MOF_INDENT, maxline,
line_pos + 1, 1, True)
if val_str[0] != '\n':
# Empty arrays are represented as val_str=''
if val_str and val_str[0] != '\n':
# The extra space was actually needed
mof.append(u' ')
else:
Expand All @@ -4798,6 +4799,7 @@ def tomof(
val_str, line_pos = _value_tomof(
self.value, self.type, indent + MOF_INDENT, maxline,
line_pos + 1, 1, True)
# Scalars cannot be represented as val_str=''
if val_str[0] != '\n':
# The extra space was actually needed
mof.append(u' ')
Expand Down Expand Up @@ -6602,7 +6604,8 @@ def tomof(self, indent=MOF_INDENT, maxline=MAX_MOF_LINE, line_pos=0):
# Assume in line_pos that the extra space would be needed
val_str, line_pos = _value_tomof(
self.value, self.type, indent, maxline, line_pos + 1, 3, True)
if val_str[0] != '\n':
# Empty arrays are represented as val_str=''
if val_str and val_str[0] != '\n':
# The extra space was actually needed
mof.append(u' ')
else:
Expand Down
39 changes: 39 additions & 0 deletions testsuite/test_cim_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -12062,6 +12062,19 @@ class Test_CIMProperty_tomof(object):
P1 = 42;\n""",
None, True
),
(
"instance uint32 array property, empty array",
CIMProperty(
name='P1',
value=list(),
type='uint32',
is_array=True,
),
True, 12,
u"""\
P1 = { };\n""",
None, CHECK_0_12_0
),
(
"instance uint32 array property, single-line",
CIMProperty(
Expand Down Expand Up @@ -15463,6 +15476,17 @@ class Test_CIMQualifier_tomof(object): # pylint: disable=too-few-public-methods
u"""Q1 ("vt=\\f,cr=\\r")""",
None, True
),
(
"string array that is empty",
CIMQualifier(
name='Q1',
value=[],
type='string',
),
12,
u"""Q1 { }""",
None, CHECK_0_12_0
),
(
"string array with a value of two items",
CIMQualifier(
Expand Down Expand Up @@ -29156,6 +29180,21 @@ class Test_CIMQualifierDeclaration_tomof(object):
Scope();""",
None, True
),
(
"string array of variable size that has an empty array value",
CIMQualifierDeclaration(
name='Q1',
type='string',
is_array=True,
array_size=None,
value=[],
),
u"""\
Qualifier Q1 : string[] = { },
Scope();
""",
None, CHECK_0_12_0
),
(
"string array of variable size",
CIMQualifierDeclaration(
Expand Down